<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Pracainzynierska: Plik źródłowy src/main.c</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Wygenerowano przez Doxygen 1.5.6 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Strona&nbsp;główna</span></a></li>
      <li><a href="annotated.html"><span>Struktury&nbsp;Danych</span></a></li>
      <li class="current"><a href="files.html"><span>Pliki</span></a></li>
    </ul>
  </div>
<h1>src/main.c</h1><a href="main_8c.html">Idź do dokumentacji tego pliku.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* ======================================================================</span>
<a name="l00002"></a>00002 <span class="comment"> *  WYBRANE PROBLEMY ALOKACJI ZASOBOW,</span>
<a name="l00003"></a>00003 <span class="comment"> *  Kacper D. Tomzynski</span>
<a name="l00004"></a>00004 <span class="comment"> *</span>
<a name="l00005"></a>00005 <span class="comment"> *  Opiekun pracy:</span>
<a name="l00006"></a>00006 <span class="comment"> *  dr inz. Krzysztof Pienkosz</span>
<a name="l00007"></a>00007 <span class="comment"> *</span>
<a name="l00008"></a>00008 <span class="comment"> *      Wydzial Elektroniki i Technik Informacyjnych Politechniki Warszawskiej</span>
<a name="l00009"></a>00009 <span class="comment"> *  2008</span>
<a name="l00010"></a>00010 <span class="comment"> * ====================================================================== */</span>
<a name="l00011"></a>00011 
<a name="l00012"></a>00012 <span class="comment">/* ======================================================================</span>
<a name="l00013"></a>00013 <span class="comment"> *  biblioteki</span>
<a name="l00014"></a>00014 <span class="comment"> * ====================================================================== */</span>
<a name="l00015"></a>00015 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00016"></a>00016 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00017"></a>00017 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &lt;time.h&gt;</span>
<a name="l00019"></a>00019 <span class="preprocessor">#include &lt;math.h&gt;</span>
<a name="l00020"></a>00020 <span class="preprocessor">#include "<a class="code" href="main_8h.html">main.h</a>"</span>
<a name="l00021"></a>00021 
<a name="l00022"></a>00022 <span class="comment">/* ======================================================================</span>
<a name="l00023"></a>00023 <span class="comment"> *  stale</span>
<a name="l00024"></a>00024 <span class="comment"> * ====================================================================== */</span>
<a name="l00025"></a>00025 
<a name="l00026"></a>00026 <span class="comment">/* dotyczy PoprawLambda */</span>
<a name="l00027"></a><a class="code" href="main_8c.html#090b5d90b0350e728a076aeef5b1184b">00027</a> <span class="preprocessor">#define ZNAJDZ_MIN_WIEKSZA 1</span>
<a name="l00028"></a><a class="code" href="main_8c.html#edc0d239bfc447fb9dc15e7a96c0a19d">00028</a> <span class="preprocessor"></span><span class="preprocessor">#define ZNAJDZ_MAX_MNIEJSZA 0</span>
<a name="l00029"></a>00029 <span class="preprocessor"></span>
<a name="l00030"></a>00030 <span class="comment">/* ======================================================================</span>
<a name="l00031"></a>00031 <span class="comment"> *  zmienne</span>
<a name="l00032"></a>00032 <span class="comment"> * ====================================================================== */</span>
<a name="l00033"></a><a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a">00033</a> <span class="keywordtype">int</span> <a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a> = 0; 
<a name="l00040"></a>00040 <span class="comment">/*-- niezmienne dla jednego rozwiazania -------------------------------------*/</span>
<a name="l00041"></a>00041 
<a name="l00042"></a><a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337">00042</a> <span class="keywordtype">int</span> <a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>=0;   
<a name="l00043"></a><a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3">00043</a> <span class="keywordtype">int</span> <a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>=0;   
<a name="l00044"></a><a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85">00044</a> <span class="keywordtype">int</span> <a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>=0;   
<a name="l00047"></a><a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c">00047</a> <span class="keywordtype">int</span>* <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>;       
<a name="l00048"></a><a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42">00048</a> <span class="keywordtype">int</span>* <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>;       
<a name="l00049"></a><a class="code" href="main_8c.html#18edff6f6f8cc7071adfd9bc826378ef">00049</a> <span class="keywordtype">double</span>* <a class="code" href="main_8c.html#18edff6f6f8cc7071adfd9bc826378ef" title="Wektor bazowych dochodowosci .">v</a>;    
<a name="l00051"></a>00051 <span class="comment">/*-- dynamiczne --------------------------------------------------------------*/</span>
<a name="l00052"></a>00052 
<a name="l00053"></a><a class="code" href="main_8c.html#eb52211fe1c73eb9c9d5568074d3013c">00053</a> <span class="keywordtype">double</span>* <a class="code" href="main_8c.html#eb52211fe1c73eb9c9d5568074d3013c" title="Wektor profitow zredukowanych, tj. .">p_</a>;   
<a name="l00054"></a><a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de">00054</a> <span class="keywordtype">double</span>* <a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de" title="Wektor zredukowanych dochodowosci .">v_</a>;   
<a name="l00057"></a><a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35">00057</a> <span class="keywordtype">int</span>* <a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>;  
<a name="l00074"></a><a class="code" href="main_8c.html#4cba98c6387bd12a0acde1fe002efd63">00074</a> <span class="keywordtype">int</span>* <a class="code" href="main_8c.html#4cba98c6387bd12a0acde1fe002efd63" title="Wektor okresla, ktory w kolejnosci malejacej dochodowosci jest i-ty podmiot. .">ki</a>;  
<a name="l00091"></a><a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909">00091</a> <span class="keywordtype">double</span>* <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>;       
<a name="l00093"></a>00093 <span class="comment">/*-- dane relaksacji ---------------------------------------------------------*/</span>
<a name="l00094"></a>00094 
<a name="l00095"></a><a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af">00095</a> <span class="keywordtype">double</span> <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a> = 0;      
<a name="l00096"></a><a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3">00096</a> <span class="keywordtype">double</span> <a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a> = 0;    
<a name="l00100"></a><a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d">00100</a> <span class="keywordtype">double</span> <a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a> = 0;    
<a name="l00104"></a><a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2">00104</a> <span class="keywordtype">int</span> <a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a> = 1;                              
<a name="l00105"></a><a class="code" href="main_8c.html#262072a74026166e1c7b6bf6f135791b">00105</a> <span class="keywordtype">int</span> <a class="code" href="main_8c.html#262072a74026166e1c7b6bf6f135791b" title="Indeks elementu granicznego (wg nomenklatury i.">i_s</a>;                                
<a name="l00107"></a><a class="code" href="main_8c.html#f60379e32a5ed1751e6034c328ca7541">00107</a> <span class="keywordtype">int</span> <a class="code" href="main_8c.html#f60379e32a5ed1751e6034c328ca7541">s_1</a>;                                
<a name="l00108"></a><a class="code" href="main_8c.html#bc16b71c93276151b863e3c1cde5fc29">00108</a> <span class="keywordtype">int</span> <a class="code" href="main_8c.html#bc16b71c93276151b863e3c1cde5fc29">s_2</a>;                                
<a name="l00110"></a><a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410">00110</a> <span class="keywordtype">double</span> <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a>;              
<a name="l00111"></a><a class="code" href="main_8c.html#ba4ddc236971684b95ae11d622e50237">00111</a> <span class="keywordtype">double</span> <a class="code" href="main_8c.html#ba4ddc236971684b95ae11d622e50237" title="Aktualna wartosc C(  ).">aktualneC</a>;       
<a name="l00112"></a><a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90">00112</a> <span class="keywordtype">double</span> <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a>; 
<a name="l00114"></a>00114 <span class="comment">/*-- zbieranie wynikow ---------------------------------------------------------*/</span>
<a name="l00115"></a>00115 
<a name="l00116"></a><a class="code" href="main_8c.html#7313b89a925c5bcdbf8b28a54018cb6a">00116</a> <span class="keywordtype">int</span> <a class="code" href="main_8c.html#7313b89a925c5bcdbf8b28a54018cb6a">czasStartowy</a>;
<a name="l00117"></a><a class="code" href="main_8c.html#6ced5c44871ebf39b65910b5726a3de0">00117</a> <span class="keywordtype">int</span> <a class="code" href="main_8c.html#6ced5c44871ebf39b65910b5726a3de0">czasAlgorytmu</a>;              
<a name="l00119"></a><a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">00119</a> <span class="keywordtype">int</span> <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a>;    
<a name="l00121"></a><a class="code" href="main_8c.html#e41c8500c68b74939c9beab3ff16990e">00121</a> <span class="preprocessor">#define REL 0</span>
<a name="l00122"></a><a class="code" href="main_8c.html#99a3a311f73faef2c0af730e7f4dd00b">00122</a> <span class="preprocessor"></span><span class="preprocessor">#define GLPK_R 1</span>
<a name="l00123"></a><a class="code" href="main_8c.html#0ac59573db46e3d633836e727f08aa0e">00123</a> <span class="preprocessor"></span><span class="preprocessor">#define GLPK_D 2</span>
<a name="l00124"></a><a class="code" href="main_8c.html#3e4baeb2553d751ae0c007569655a137">00124</a> <span class="preprocessor"></span><span class="preprocessor">#define H1 3</span>
<a name="l00125"></a><a class="code" href="main_8c.html#b5e8a97982062958fb8f58a428df09ee">00125</a> <span class="preprocessor"></span><span class="preprocessor">#define H2 4</span>
<a name="l00126"></a><a class="code" href="main_8c.html#e3ea6c504e916b75b4e44abeffdb8477">00126</a> <span class="preprocessor"></span><span class="preprocessor">#define H2P 5</span>
<a name="l00127"></a><a class="code" href="main_8c.html#13ba4f47dcd4f3e4a0dca6330c1916f2">00127</a> <span class="preprocessor"></span><span class="preprocessor">#define H2B 6</span>
<a name="l00128"></a>00128 <span class="preprocessor"></span>
<a name="l00129"></a><a class="code" href="main_8c.html#29b4c5424b00e8c417f6cd28b91c6246">00129</a> <span class="keywordtype">char</span>* <a class="code" href="main_8c.html#29b4c5424b00e8c417f6cd28b91c6246">nazwy</a>[] = {<span class="stringliteral">"REL "</span>,<span class="stringliteral">"LP_R"</span>, <span class="stringliteral">"LP_D"</span>, <span class="stringliteral">"H1  "</span>, <span class="stringliteral">"H2  "</span>, <span class="stringliteral">"H2P "</span>, <span class="stringliteral">"H2B "</span>};
<a name="l00130"></a><a class="code" href="main_8c.html#2dc32c866ea1d483256f14beab4f0859">00130</a> <span class="keywordtype">int</span> <a class="code" href="main_8c.html#2dc32c866ea1d483256f14beab4f0859">wynikIteracje</a>[7];
<a name="l00131"></a><a class="code" href="main_8c.html#bc046b760068e2015d1f943257ad1c9d">00131</a> <span class="keywordtype">double</span> <a class="code" href="main_8c.html#bc046b760068e2015d1f943257ad1c9d">wynikAlokacja</a>[7];
<a name="l00132"></a><a class="code" href="main_8c.html#b0c1a864c503ead10e2426d29c03fcc5">00132</a> <span class="keywordtype">int</span> <a class="code" href="main_8c.html#b0c1a864c503ead10e2426d29c03fcc5">wynikCzas</a>[7];
<a name="l00133"></a>00133 
<a name="l00134"></a>00134 
<a name="l00135"></a>00135 <span class="comment">/*-- informacje o plikach we-wy ------------------------------------------------*/</span>
<a name="l00136"></a>00136 
<a name="l00137"></a><a class="code" href="main_8c.html#e401adba12fa394291ec56e59e8120f4">00137</a> <span class="keywordtype">char</span> <a class="code" href="main_8c.html#e401adba12fa394291ec56e59e8120f4">nazwaPlikuWejsciowego</a>[64];
<a name="l00138"></a><a class="code" href="main_8c.html#dcbfa19007dff19a1e3a32c137445ea2">00138</a> FILE * <a class="code" href="main_8c.html#dcbfa19007dff19a1e3a32c137445ea2">PlikLogu</a>;
<a name="l00139"></a><a class="code" href="main_8c.html#7c91f2a453eee2b8246c3eb270920175">00139</a> <span class="keywordtype">char</span> <a class="code" href="main_8c.html#7c91f2a453eee2b8246c3eb270920175">dodatkoweInformacje</a>[128];
<a name="l00140"></a>00140 
<a name="l00141"></a>00141 <span class="comment">/* ======================================================================</span>
<a name="l00142"></a>00142 <span class="comment"> * **********************************************************************</span>
<a name="l00143"></a>00143 <span class="comment"> *  FUNKCJE</span>
<a name="l00144"></a>00144 <span class="comment"> *  *********************************************************************</span>
<a name="l00145"></a>00145 <span class="comment"> * ====================================================================== */</span>
<a name="l00146"></a>00146 
<a name="l00147"></a>00147 
<a name="l00148"></a>00148 <span class="comment">/* ======================================================================</span>
<a name="l00149"></a>00149 <span class="comment"> *  WczytajDaneWejsciowe</span>
<a name="l00150"></a>00150 <span class="comment"> * ====================================================================== */</span>
<a name="l00175"></a><a class="code" href="main_8c.html#32d9cda086dbd06f8c1fe3f430611d9a">00175</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#32d9cda086dbd06f8c1fe3f430611d9a" title="Wczytuje dane z pliku.">WczytajDaneWejsciowe</a>(<span class="keywordtype">char</span>* plikWejsciowy)
<a name="l00176"></a>00176 {
<a name="l00177"></a>00177     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00178"></a>00178         printf (<span class="stringliteral">"---- readInputData(%s) ----\n"</span>,plikWejsciowy);
<a name="l00179"></a>00179     FILE *fp;
<a name="l00180"></a>00180 
<a name="l00181"></a>00181     <span class="keywordflow">if</span> ((fp=fopen(plikWejsciowy, <span class="stringliteral">"r"</span>))==NULL)
<a name="l00182"></a>00182     {
<a name="l00183"></a>00183         printf(<span class="stringliteral">"Nie mozna otworzyc qliku '%s' !\n"</span>,plikWejsciowy);
<a name="l00184"></a>00184         exit(1);
<a name="l00185"></a>00185     }
<a name="l00186"></a>00186     <span class="keywordflow">else</span>
<a name="l00187"></a>00187         (printf(<span class="stringliteral">"Czytanie danych z pliku '%s'...\n"</span>,plikWejsciowy));
<a name="l00188"></a>00188 
<a name="l00189"></a>00189     strcpy(<a class="code" href="main_8c.html#e401adba12fa394291ec56e59e8120f4">nazwaPlikuWejsciowego</a>,plikWejsciowy);
<a name="l00190"></a>00190 
<a name="l00191"></a>00191     fscanf(fp,<span class="stringliteral">"%u"</span>,&amp;<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>);
<a name="l00192"></a>00192     fscanf(fp,<span class="stringliteral">"\n"</span>);
<a name="l00193"></a>00193     fscanf(fp,<span class="stringliteral">"%u"</span>,&amp;<a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>);
<a name="l00194"></a>00194     fscanf(fp,<span class="stringliteral">"\n"</span>);
<a name="l00195"></a>00195     fscanf(fp,<span class="stringliteral">"%d"</span>,&amp;<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>);
<a name="l00196"></a>00196     fscanf(fp,<span class="stringliteral">"\n\n"</span>);
<a name="l00197"></a>00197 
<a name="l00198"></a>00198     printf(<span class="stringliteral">"Alokacja pamieci...\n"</span>);
<a name="l00199"></a>00199     <a class="code" href="main_8c.html#bbeebdb30d90a79d95cab377a59f62f0" title="Dynamiczny alokator danych.">AlokujPamiec</a>(<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>);
<a name="l00200"></a>00200 
<a name="l00201"></a>00201     <span class="keywordtype">int</span> i = 1;
<a name="l00202"></a>00202     <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00203"></a>00203         fscanf(fp,<span class="stringliteral">"%u\t%u\n"</span>,<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>+i,<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>+i);
<a name="l00204"></a>00204     fclose(fp);
<a name="l00205"></a>00205 
<a name="l00206"></a>00206     printf(<span class="stringliteral">"\nWczytano poprawnie : \nN = %d\nK = %d\nc = %d\n"</span>,<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>,<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>,<a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>);
<a name="l00207"></a>00207 
<a name="l00208"></a>00208     <a class="code" href="main_8c.html#86892a380cb93ebd030dba5a6302be06" title="Inicjalizuje czesc wektorow.">InicjujDane</a>();
<a name="l00209"></a>00209 
<a name="l00210"></a>00210     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00211"></a>00211         printf (<span class="stringliteral">"---- readInputData KONIEC ----\n"</span>);
<a name="l00212"></a>00212 
<a name="l00213"></a>00213 }
<a name="l00214"></a>00214 
<a name="l00215"></a>00215 <span class="comment">/* ======================================================================</span>
<a name="l00216"></a>00216 <span class="comment"> *  AlokujPamiec</span>
<a name="l00217"></a>00217 <span class="comment"> * ====================================================================== */</span>
<a name="l00225"></a><a class="code" href="main_8h.html#80c4e8d2623ecf8dd7f52e97fff4a981">00225</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#bbeebdb30d90a79d95cab377a59f62f0" title="Dynamiczny alokator danych.">AlokujPamiec</a>(<span class="keywordtype">int</span> liczbaElementow)
<a name="l00226"></a>00226 {
<a name="l00227"></a>00227     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00228"></a>00228         printf(<span class="stringliteral">"---- ALLOC DATA ARRAYS(%d) ---\n"</span>,liczbaElementow);
<a name="l00229"></a>00229     <span class="comment">/* "1+" wektory indeksowane sa od jedynki, dlatego potrzebujemy wiecej miejsca */</span>
<a name="l00230"></a>00230 
<a name="l00231"></a>00231     <span class="keywordtype">int</span> NoE = 1+liczbaElementow;
<a name="l00232"></a>00232     <span class="comment">/* stale */</span>
<a name="l00233"></a>00233     <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a> = (<span class="keywordtype">int</span> *) malloc(NoE * <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
<a name="l00234"></a>00234     <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a> = (<span class="keywordtype">int</span> *) malloc(NoE * <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
<a name="l00235"></a>00235     <a class="code" href="main_8c.html#18edff6f6f8cc7071adfd9bc826378ef" title="Wektor bazowych dochodowosci .">v</a> = (<span class="keywordtype">double</span> *) malloc(NoE * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
<a name="l00236"></a>00236 
<a name="l00237"></a>00237     <span class="comment">/* zmienne w czasie wykonywania programu */</span>
<a name="l00238"></a>00238     <a class="code" href="main_8c.html#eb52211fe1c73eb9c9d5568074d3013c" title="Wektor profitow zredukowanych, tj. .">p_</a> = (<span class="keywordtype">double</span> *) malloc(NoE * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
<a name="l00239"></a>00239     <a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de" title="Wektor zredukowanych dochodowosci .">v_</a> = (<span class="keywordtype">double</span> *) malloc(NoE * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
<a name="l00240"></a>00240 
<a name="l00241"></a>00241     <a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a> = (<span class="keywordtype">int</span> *) malloc(NoE * <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
<a name="l00242"></a>00242     <a class="code" href="main_8c.html#4cba98c6387bd12a0acde1fe002efd63" title="Wektor okresla, ktory w kolejnosci malejacej dochodowosci jest i-ty podmiot. .">ki</a> = (<span class="keywordtype">int</span> *) malloc(NoE * <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
<a name="l00243"></a>00243 
<a name="l00244"></a>00244     <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a> = (<span class="keywordtype">double</span> *) malloc(NoE * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
<a name="l00245"></a>00245 
<a name="l00246"></a>00246 
<a name="l00247"></a>00247     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00248"></a>00248         printf(<span class="stringliteral">"---- ALLOC DATA ARRAYS KONIEC. ----\n"</span>);
<a name="l00249"></a>00249 }
<a name="l00250"></a>00250 
<a name="l00251"></a>00251 <span class="comment">/* ======================================================================</span>
<a name="l00252"></a>00252 <span class="comment"> *  CZEKAJ</span>
<a name="l00253"></a>00253 <span class="comment"> * ====================================================================== */</span>
<a name="l00258"></a><a class="code" href="main_8c.html#64eaf90839462ac6338df2ecca303987">00258</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#64eaf90839462ac6338df2ecca303987" title="Funkcja wstrzymuje dzialanie programu na okreslona liczbe sekund.">Czekaj</a>(<span class="keywordtype">int</span> ileSekund)
<a name="l00259"></a>00259 {
<a name="l00260"></a>00260     time_t start = time(NULL);
<a name="l00261"></a>00261     <span class="keywordflow">while</span>(difftime(time(NULL),start)&lt;ileSekund)
<a name="l00262"></a>00262     {
<a name="l00263"></a>00263         ; <span class="comment">//nic nie rob</span>
<a name="l00264"></a>00264     }
<a name="l00265"></a>00265 }
<a name="l00266"></a>00266 
<a name="l00267"></a>00267 <span class="comment">/* ======================================================================</span>
<a name="l00268"></a>00268 <span class="comment"> *  Czas start</span>
<a name="l00269"></a>00269 <span class="comment"> * ====================================================================== */</span>
<a name="l00274"></a><a class="code" href="main_8c.html#e9284b236f128677657631ae56843cae">00274</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#e9284b236f128677657631ae56843cae" title="Funkcja wstrzymuje dzialanie programu na okreslona liczbe sekund.">CzasStart</a>()
<a name="l00275"></a>00275 {
<a name="l00276"></a>00276     <a class="code" href="main_8c.html#7313b89a925c5bcdbf8b28a54018cb6a">czasStartowy</a> = clock();
<a name="l00277"></a>00277 }
<a name="l00278"></a>00278 
<a name="l00279"></a><a class="code" href="main_8c.html#2cc2c7e7811c4a88e4dc3ee60b801508">00279</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#2cc2c7e7811c4a88e4dc3ee60b801508">CzasStop</a>()
<a name="l00280"></a>00280 {
<a name="l00281"></a>00281     <a class="code" href="main_8c.html#6ced5c44871ebf39b65910b5726a3de0">czasAlgorytmu</a> = (int)((clock()-<a class="code" href="main_8c.html#7313b89a925c5bcdbf8b28a54018cb6a">czasStartowy</a>)*1E3/CLOCKS_PER_SEC);
<a name="l00282"></a>00282 }
<a name="l00283"></a>00283 
<a name="l00284"></a>00284 <span class="comment">/* ======================================================================</span>
<a name="l00285"></a>00285 <span class="comment"> *  Zapisz wyniki</span>
<a name="l00286"></a>00286 <span class="comment"> * ====================================================================== */</span>
<a name="l00305"></a><a class="code" href="main_8c.html#7ff0e94f5e3c9337353542d81db57104">00305</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#7ff0e94f5e3c9337353542d81db57104" title="Generuje pliki wynikowe dla odpowiednich algorytmow.">ZapiszWyniki</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *nazwaPliku)
<a name="l00306"></a>00306 {
<a name="l00307"></a>00307     FILE *Plik;
<a name="l00308"></a>00308     <span class="keywordflow">if</span> (((Plik=fopen(nazwaPliku, <span class="stringliteral">"w"</span>))==NULL))
<a name="l00309"></a>00309     {
<a name="l00310"></a>00310         printf(<span class="stringliteral">"Nie mozna otworzyc pliku wyjsciowego '%s' do zapisu.\n"</span>,nazwaPliku);
<a name="l00311"></a>00311         exit(1);
<a name="l00312"></a>00312     }
<a name="l00313"></a>00313     <span class="keywordflow">else</span>
<a name="l00314"></a>00314         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00315"></a>00315             printf(<span class="stringliteral">"\n\nOtwarto plik do zapisu.\n"</span>);
<a name="l00316"></a>00316 
<a name="l00317"></a>00317     fprintf(Plik,<span class="stringliteral">"Dane: %s\n"</span>,<a class="code" href="main_8c.html#e401adba12fa394291ec56e59e8120f4">nazwaPlikuWejsciowego</a>);
<a name="l00318"></a>00318     fprintf(Plik,<span class="stringliteral">"N = %d, c = %d, K = %d\n"</span>,<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>,<a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>,<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>);
<a name="l00319"></a>00319 
<a name="l00320"></a>00320     fprintf(Plik,<span class="stringliteral">"\nAlgorytm : %s\n"</span>,<a class="code" href="main_8c.html#7c91f2a453eee2b8246c3eb270920175">dodatkoweInformacje</a>);
<a name="l00321"></a>00321 
<a name="l00322"></a>00322     fprintf(Plik,<span class="stringliteral">"\nz = %f\n"</span>,<a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a>);
<a name="l00323"></a>00323     fprintf(Plik,<span class="stringliteral">"czas = %d\n"</span>,<a class="code" href="main_8c.html#6ced5c44871ebf39b65910b5726a3de0">czasAlgorytmu</a>);
<a name="l00324"></a>00324     fprintf(Plik,<span class="stringliteral">"iteracje = %d\n"</span>,<a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a>);
<a name="l00325"></a>00325     fprintf(Plik,<span class="stringliteral">"\nRozwiazanie:\n"</span>);
<a name="l00326"></a>00326     <span class="keywordtype">int</span> i;
<a name="l00327"></a>00327     <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00328"></a>00328         fprintf(Plik,<span class="stringliteral">"x[%d] = %f\n"</span>,i,<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[i]);
<a name="l00329"></a>00329 }
<a name="l00330"></a>00330 
<a name="l00331"></a>00331 <span class="comment">/* ======================================================================</span>
<a name="l00332"></a>00332 <span class="comment"> *  WYNIKI ZBIORCZE</span>
<a name="l00333"></a>00333 <span class="comment"> * ====================================================================== */</span>
<a name="l00338"></a><a class="code" href="main_8c.html#8bd72ae940fe946b5943662c5c41fd7a">00338</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#8bd72ae940fe946b5943662c5c41fd7a" title="Generuje plik z rozwiazaniem zbiorczym dla wielu algorytmow.">WynikiZbiorcze</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *nazwaPliku)
<a name="l00339"></a>00339 {
<a name="l00340"></a>00340     FILE *Plik;
<a name="l00341"></a>00341     <span class="keywordflow">if</span> (((Plik=fopen(nazwaPliku, <span class="stringliteral">"w"</span>))==NULL))
<a name="l00342"></a>00342     {
<a name="l00343"></a>00343         printf(<span class="stringliteral">"Nie mozna otworzyc pliku wyjsciowego '%s' do zapisu.\n"</span>,nazwaPliku);
<a name="l00344"></a>00344         exit(1);
<a name="l00345"></a>00345     }
<a name="l00346"></a>00346     <span class="keywordflow">else</span>
<a name="l00347"></a>00347         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00348"></a>00348             printf(<span class="stringliteral">"\n\nOtwarto plik do zapisu.\n"</span>);
<a name="l00349"></a>00349 
<a name="l00350"></a>00350 
<a name="l00351"></a>00351     fprintf(Plik,<span class="stringliteral">"Dane: %s\n"</span>,<a class="code" href="main_8c.html#e401adba12fa394291ec56e59e8120f4">nazwaPlikuWejsciowego</a>);
<a name="l00352"></a>00352     fprintf(Plik,<span class="stringliteral">"N = %d, c = %d, K = %d\n"</span>,<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>,<a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>,<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>);
<a name="l00353"></a>00353 
<a name="l00354"></a>00354     <span class="keywordtype">int</span> i=0;
<a name="l00355"></a>00355     fprintf(Plik,<span class="stringliteral">"\n\nALG\t\t\tZ\t\t\tCZAS\tITERACJE\n"</span>);
<a name="l00356"></a>00356     <span class="keywordflow">for</span>(i=0;i&lt;=50;i++)
<a name="l00357"></a>00357         fprintf(Plik,<span class="stringliteral">"-"</span>);
<a name="l00358"></a>00358     <span class="keywordflow">for</span> (i=0; i&lt;7; i++)
<a name="l00359"></a>00359         fprintf(Plik,<span class="stringliteral">"\n%s\t\t%f\t%d\t\t%d"</span>,<a class="code" href="main_8c.html#29b4c5424b00e8c417f6cd28b91c6246">nazwy</a>[i],<a class="code" href="main_8c.html#bc046b760068e2015d1f943257ad1c9d">wynikAlokacja</a>[i],<a class="code" href="main_8c.html#b0c1a864c503ead10e2426d29c03fcc5">wynikCzas</a>[i],<a class="code" href="main_8c.html#2dc32c866ea1d483256f14beab4f0859">wynikIteracje</a>[i]);
<a name="l00360"></a>00360 
<a name="l00361"></a>00361     fprintf(Plik,<span class="stringliteral">"\n\nDANE WEJSCIOWE:\n"</span>);
<a name="l00362"></a>00362     <span class="keywordflow">for</span> (i=0;i&lt;=20; i++)
<a name="l00363"></a>00363         fprintf(Plik,<span class="stringliteral">"-"</span>);
<a name="l00364"></a>00364     fprintf(Plik,<span class="stringliteral">"\ni\tp\tw\n"</span>);
<a name="l00365"></a>00365     <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00366"></a>00366         fprintf(Plik,<span class="stringliteral">"%d\t%d\t%d\n"</span>,i,<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i],<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i]);
<a name="l00367"></a>00367 
<a name="l00368"></a>00368     fclose(Plik);
<a name="l00369"></a>00369 }
<a name="l00370"></a>00370 
<a name="l00371"></a>00371 <span class="comment">/* ======================================================================</span>
<a name="l00372"></a>00372 <span class="comment"> *  genDataInstance</span>
<a name="l00373"></a>00373 <span class="comment"> * ====================================================================== */</span>
<a name="l00385"></a><a class="code" href="structopts.html">00385</a> <span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code" href="structopts.html" title="Tworzy jeden zbior danych (N par [p,w]), funkcja jest sterowana struktura params...">opts</a>
<a name="l00386"></a>00386 {
<a name="l00387"></a><a class="code" href="structopts.html#cf0540f1aa9b5e94765411e284c05dcd">00387</a>     <span class="keywordtype">int</span> <a class="code" href="structopts.html#816bc5109ed7446ec83bbdc7590c9f5d">pmax</a>, <a class="code" href="structopts.html#cf0540f1aa9b5e94765411e284c05dcd">pmin</a>;
<a name="l00388"></a><a class="code" href="structopts.html#5b32b7d52b6cb87bb1a4a424ad272610">00388</a>     <span class="keywordtype">int</span> <a class="code" href="structopts.html#fd8f77858d4852089005be9eede15361">wmax</a>, <a class="code" href="structopts.html#5b32b7d52b6cb87bb1a4a424ad272610">wmin</a>;     <span class="comment">/* */</span>
<a name="l00389"></a><a class="code" href="structopts.html#c83477f23d05b36f236e68ff1675d9f9">00389</a>     <span class="keywordtype">int</span> <a class="code" href="structopts.html#c83477f23d05b36f236e68ff1675d9f9">strict</a>;         <span class="comment">/* p = w + strict                       */</span>
<a name="l00390"></a><a class="code" href="structopts.html#85b15c40539213a33716c5eccd5e787a">00390</a>     <span class="keywordtype">int</span> <a class="code" href="structopts.html#85b15c40539213a33716c5eccd5e787a">R</a>;                      <span class="comment">/* p nalezy do &lt;w-R,w+R&gt;        */</span>
<a name="l00391"></a>00391 }
<a name="l00392"></a>00392 <a class="code" href="structopts.html" title="Tworzy jeden zbior danych (N par [p,w]), funkcja jest sterowana struktura params...">gdi_params</a>;
<a name="l00393"></a>00393 
<a name="l00394"></a>00394 
<a name="l00395"></a>00395 <span class="comment">/* ======================================================================</span>
<a name="l00396"></a>00396 <span class="comment"> *  genDataInstance</span>
<a name="l00397"></a>00397 <span class="comment"> * ====================================================================== */</span>
<a name="l00409"></a><a class="code" href="main_8c.html#8a11d2a89a222228b20af3244b441003">00409</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#8a11d2a89a222228b20af3244b441003" title="Tworzy jeden zbior danych (N par [p,w]), funkcja jest sterowana struktura params...">genDataInstance</a>(<span class="keywordtype">int</span> intN, <span class="keywordtype">int</span> wfunc, <span class="keywordtype">int</span> pfunc, <span class="keywordtype">int</span> *w_params, <span class="keywordtype">int</span> *p_params)
<a name="l00410"></a>00410 {
<a name="l00411"></a>00411     srand(time(NULL));
<a name="l00412"></a>00412     <a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a> = intN;
<a name="l00413"></a>00413     <span class="keywordtype">int</span> i;
<a name="l00414"></a>00414     <span class="keywordflow">switch</span> (wfunc)
<a name="l00415"></a>00415     {
<a name="l00416"></a>00416         <span class="comment">// w zbiorze &lt;w_0 - delta_w, w_0 + delta_w&gt;</span>
<a name="l00417"></a>00417         <span class="comment">// w_0 = params[0]</span>
<a name="l00418"></a>00418         <span class="comment">// delta_w = params[1]</span>
<a name="l00419"></a>00419     <span class="keywordflow">case</span> 1:
<a name="l00420"></a>00420         <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00421"></a>00421             <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i] = w_params[0]-w_params[1]+2*(rand()%w_params[1]);
<a name="l00422"></a>00422         <span class="keywordflow">break</span>;
<a name="l00423"></a>00423     <span class="keywordflow">default</span>:
<a name="l00424"></a>00424             <span class="keywordflow">break</span>;
<a name="l00425"></a>00425     }
<a name="l00426"></a>00426 
<a name="l00427"></a>00427     <span class="keywordflow">switch</span> (pfunc)
<a name="l00428"></a>00428     {
<a name="l00429"></a>00429         <span class="comment">// p = w</span>
<a name="l00430"></a>00430     <span class="keywordflow">case</span> 1:
<a name="l00431"></a>00431         <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00432"></a>00432             <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i] = <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i];
<a name="l00433"></a>00433         <span class="keywordflow">break</span>;
<a name="l00434"></a>00434 
<a name="l00435"></a>00435         <span class="comment">// p = w + delta_p</span>
<a name="l00436"></a>00436         <span class="comment">// delta_p = p_params[0]</span>
<a name="l00437"></a>00437     <span class="keywordflow">case</span> 2:
<a name="l00438"></a>00438             <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00439"></a>00439                 <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i] = <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i] + p_params[0];
<a name="l00440"></a>00440         <span class="keywordflow">break</span>;
<a name="l00441"></a>00441 
<a name="l00442"></a>00442         <span class="comment">// p = &lt;w - delta_p, w + delta_p&gt;</span>
<a name="l00443"></a>00443         <span class="comment">// delta_p = p_params[0]</span>
<a name="l00444"></a>00444     <span class="keywordflow">case</span> 3:
<a name="l00445"></a>00445             <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00446"></a>00446                 <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i] = <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i] - p_params[0] + 2*(rand()%p_params[0]);
<a name="l00447"></a>00447         <span class="keywordflow">break</span>;
<a name="l00448"></a>00448 
<a name="l00449"></a>00449         <span class="comment">// domyslnie - p random [1,100]</span>
<a name="l00450"></a>00450     <span class="keywordflow">default</span>:
<a name="l00451"></a>00451             <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00452"></a>00452                 <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i] = 1 + rand()%100;
<a name="l00453"></a>00453         <span class="keywordflow">break</span>;
<a name="l00454"></a>00454     }
<a name="l00455"></a>00455 }
<a name="l00456"></a>00456 
<a name="l00457"></a>00457 <span class="comment">/* ======================================================================</span>
<a name="l00458"></a>00458 <span class="comment"> *  InicjujDane</span>
<a name="l00459"></a>00459 <span class="comment"> * ====================================================================== */</span>
<a name="l00478"></a><a class="code" href="main_8h.html#86892a380cb93ebd030dba5a6302be06">00478</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#86892a380cb93ebd030dba5a6302be06" title="Inicjalizuje czesc wektorow.">InicjujDane</a>()
<a name="l00479"></a>00479 {
<a name="l00480"></a>00480     <span class="keywordtype">int</span> i;
<a name="l00481"></a>00481     <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a> = 0;
<a name="l00482"></a>00482 
<a name="l00483"></a>00483     <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00484"></a>00484     {
<a name="l00485"></a>00485         <a class="code" href="main_8c.html#eb52211fe1c73eb9c9d5568074d3013c" title="Wektor profitow zredukowanych, tj. .">p_</a>[i] = <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i];
<a name="l00486"></a>00486         <a class="code" href="main_8c.html#18edff6f6f8cc7071adfd9bc826378ef" title="Wektor bazowych dochodowosci .">v</a>[i] = (double)<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i]/<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i];
<a name="l00487"></a>00487         <a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de" title="Wektor zredukowanych dochodowosci .">v_</a>[i] = <a class="code" href="main_8c.html#18edff6f6f8cc7071adfd9bc826378ef" title="Wektor bazowych dochodowosci .">v</a>[i];
<a name="l00488"></a>00488         <a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i] = i;
<a name="l00489"></a>00489         <a class="code" href="main_8c.html#4cba98c6387bd12a0acde1fe002efd63" title="Wektor okresla, ktory w kolejnosci malejacej dochodowosci jest i-ty podmiot. .">ki</a>[i] = i;
<a name="l00490"></a>00490         <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[i] = 0;
<a name="l00491"></a>00491     }
<a name="l00492"></a>00492 
<a name="l00493"></a>00493     <a class="code" href="main_8c.html#362a3c1431859c5851d11cf139c74b31">SortujB</a>();
<a name="l00494"></a>00494 }
<a name="l00495"></a>00495 
<a name="l00496"></a>00496 
<a name="l00497"></a>00497 <span class="comment">/* ======================================================================</span>
<a name="l00498"></a>00498 <span class="comment"> *  SortujB</span>
<a name="l00499"></a>00499 <span class="comment"> * ====================================================================== */</span>
<a name="l00500"></a><a class="code" href="main_8h.html#362a3c1431859c5851d11cf139c74b31">00500</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#362a3c1431859c5851d11cf139c74b31">SortujB</a>()
<a name="l00501"></a>00501 {
<a name="l00502"></a>00502     <span class="keywordtype">int</span> i,j;
<a name="l00503"></a>00503 
<a name="l00504"></a>00504     <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00505"></a>00505         <span class="keywordflow">for</span> (j=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; j&gt;=i+1; j--)
<a name="l00506"></a>00506             <span class="keywordflow">if</span> ( (<a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de" title="Wektor zredukowanych dochodowosci .">v_</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j-1]] &lt; <a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de" title="Wektor zredukowanych dochodowosci .">v_</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j]]) || ( (fabs(<a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de" title="Wektor zredukowanych dochodowosci .">v_</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j]]-<a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de" title="Wektor zredukowanych dochodowosci .">v_</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j-1]])&lt;10e-15) &amp;&amp; (<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j-1]]&gt;<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j]]) ))
<a name="l00507"></a>00507             {
<a name="l00508"></a>00508                 <span class="keywordtype">int</span> tmp = <a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j-1];
<a name="l00509"></a>00509                 <a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j-1] = <a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j];
<a name="l00510"></a>00510                 <a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j] = tmp;
<a name="l00511"></a>00511             }
<a name="l00512"></a>00512 
<a name="l00513"></a>00513     <span class="keywordtype">int</span> k;
<a name="l00514"></a>00514     <span class="keywordflow">for</span> (k=1; k&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; k++)
<a name="l00515"></a>00515         <a class="code" href="main_8c.html#4cba98c6387bd12a0acde1fe002efd63" title="Wektor okresla, ktory w kolejnosci malejacej dochodowosci jest i-ty podmiot. .">ki</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] = k; <span class="comment">// zapewnienie poprawnego ulozenia wektora ki</span>
<a name="l00516"></a>00516 
<a name="l00517"></a>00517 }
<a name="l00518"></a>00518 
<a name="l00519"></a>00519 <span class="comment">/* ======================================================================</span>
<a name="l00520"></a>00520 <span class="comment"> *  WypiszWektory</span>
<a name="l00521"></a>00521 <span class="comment"> * ====================================================================== */</span>
<a name="l00527"></a><a class="code" href="main_8c.html#644a6088014dbafc3c8055c4801a9a7b">00527</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#644a6088014dbafc3c8055c4801a9a7b">WypiszWektory</a>(<span class="keywordtype">int</span> vector_mask, <span class="keywordtype">int</span> sort_option)
<a name="l00528"></a>00528 {
<a name="l00529"></a>00529     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00530"></a>00530         printf(<span class="stringliteral">"---- printVectors(maska: %d, sortowanie: %s) ----\n"</span>,vector_mask,(sort_option &amp; <a class="code" href="main_8h.html#6c2e0ef3768d7df3cd7565c3d4d5a944">SORT_I</a>) ? <span class="stringliteral">"indeksy"</span> : <span class="stringliteral">"dochodowosci"</span>);
<a name="l00531"></a>00531     <span class="keywordtype">int</span> i,k;
<a name="l00532"></a>00532     <span class="keywordflow">if</span> ((sort_option == SORT_I) &amp;&amp; (vector_mask &amp;&amp; <a class="code" href="main_8h.html#58961bee5268baf32d9ca9ac51bcf126">MSK_INDEX</a>))
<a name="l00533"></a>00533     {
<a name="l00534"></a>00534         <span class="keywordflow">if</span> (vector_mask &amp; <a class="code" href="main_8h.html#7f0b6817300121163223ef6a0a6303f5">MSK_TYTUL</a>)
<a name="l00535"></a>00535         {
<a name="l00536"></a>00536             printf(<span class="stringliteral">"\n\nPosortowane wg. poczatkowych indeksow :\n"</span>);
<a name="l00537"></a>00537         }
<a name="l00538"></a>00538         printf(<span class="stringliteral">" i = ["</span>);
<a name="l00539"></a>00539         <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00540"></a>00540             printf(<span class="stringliteral">" %8d"</span>,i);
<a name="l00541"></a>00541         printf(<span class="stringliteral">"   ]\n"</span>);
<a name="l00542"></a>00542 
<a name="l00543"></a>00543         printf(<span class="stringliteral">" k = ["</span>);
<a name="l00544"></a>00544         <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00545"></a>00545             printf(<span class="stringliteral">" %8d"</span>,<a class="code" href="main_8c.html#4cba98c6387bd12a0acde1fe002efd63" title="Wektor okresla, ktory w kolejnosci malejacej dochodowosci jest i-ty podmiot. .">ki</a>[i]);
<a name="l00546"></a>00546         printf(<span class="stringliteral">"   ]\n"</span>);
<a name="l00547"></a>00547     }
<a name="l00548"></a>00548     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (vector_mask &amp;&amp; <a class="code" href="main_8h.html#58961bee5268baf32d9ca9ac51bcf126">MSK_INDEX</a>)
<a name="l00549"></a>00549     {
<a name="l00550"></a>00550         <span class="keywordflow">if</span> (vector_mask &amp; <a class="code" href="main_8h.html#7f0b6817300121163223ef6a0a6303f5">MSK_TYTUL</a>)
<a name="l00551"></a>00551         {
<a name="l00552"></a>00552             printf(<span class="stringliteral">"\n\nPosortowane wg. malejacych wskaznikow dochodowosci :\n"</span>);
<a name="l00553"></a>00553         }
<a name="l00554"></a>00554         printf(<span class="stringliteral">" k = ["</span>);
<a name="l00555"></a>00555         <span class="keywordflow">for</span> (k=1; k&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; k++)
<a name="l00556"></a>00556             printf(<span class="stringliteral">" %8d"</span>,k);
<a name="l00557"></a>00557         printf(<span class="stringliteral">"   ]\n"</span>);
<a name="l00558"></a>00558 
<a name="l00559"></a>00559         printf(<span class="stringliteral">" i = ["</span>);
<a name="l00560"></a>00560         <span class="keywordflow">for</span> (k=1; k&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; k++)
<a name="l00561"></a>00561             printf(<span class="stringliteral">" %8d"</span>,<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>
<a name="l00562"></a>00562 
<a name="l00563"></a>00563                    [k]);
<a name="l00564"></a>00564         printf(<span class="stringliteral">"   ]\n"</span>);
<a name="l00565"></a>00565     }
<a name="l00566"></a>00566 
<a name="l00567"></a>00567     <span class="keywordflow">if</span> (vector_mask &amp; <a class="code" href="main_8h.html#e00a20f61164fb74cb09105d2f4348c8">MSK_P</a>)
<a name="l00568"></a>00568     {
<a name="l00569"></a>00569         printf(<span class="stringliteral">" p = ["</span>);
<a name="l00570"></a>00570         <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00571"></a>00571         {
<a name="l00572"></a>00572             <span class="keywordflow">if</span> (sort_option == SORT_I)
<a name="l00573"></a>00573                 printf(<span class="stringliteral">" %8d"</span>,<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i]);
<a name="l00574"></a>00574             <span class="keywordflow">if</span> (sort_option == <a class="code" href="main_8h.html#f2c5fd4a2157bbaddee5c93c0cbebb2f">SORT_K</a>)
<a name="l00575"></a>00575                 printf(<span class="stringliteral">" %8d"</span>,<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]]);
<a name="l00576"></a>00576         }
<a name="l00577"></a>00577         printf(<span class="stringliteral">"   ]\n"</span>);
<a name="l00578"></a>00578     }
<a name="l00579"></a>00579 
<a name="l00580"></a>00580     <span class="keywordflow">if</span>  (vector_mask &amp; <a class="code" href="main_8h.html#c4c455795b32257010c9be2b845bddce">MSK_P_</a>)
<a name="l00581"></a>00581     {
<a name="l00582"></a>00582         printf(<span class="stringliteral">" p_= [ "</span>);
<a name="l00583"></a>00583         <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00584"></a>00584         {
<a name="l00585"></a>00585             <span class="keywordflow">if</span> (sort_option == SORT_I)
<a name="l00586"></a>00586                 printf(<span class="stringliteral">" %7.4f "</span>,<a class="code" href="main_8c.html#eb52211fe1c73eb9c9d5568074d3013c" title="Wektor profitow zredukowanych, tj. .">p_</a>[i]);
<a name="l00587"></a>00587             <span class="keywordflow">if</span> (sort_option == <a class="code" href="main_8h.html#f2c5fd4a2157bbaddee5c93c0cbebb2f">SORT_K</a>)
<a name="l00588"></a>00588                 printf(<span class="stringliteral">" %7.4f "</span>,<a class="code" href="main_8c.html#eb52211fe1c73eb9c9d5568074d3013c" title="Wektor profitow zredukowanych, tj. .">p_</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]]);
<a name="l00589"></a>00589         }
<a name="l00590"></a>00590         printf(<span class="stringliteral">"  ]\n"</span>);
<a name="l00591"></a>00591     }
<a name="l00592"></a>00592     <span class="keywordflow">if</span> (vector_mask &amp; <a class="code" href="main_8h.html#4c4b917a9256232b587e9af27900045e">MSK_W</a>)
<a name="l00593"></a>00593     {
<a name="l00594"></a>00594         printf(<span class="stringliteral">" w = ["</span>);
<a name="l00595"></a>00595         <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00596"></a>00596         {
<a name="l00597"></a>00597             <span class="keywordflow">if</span> (sort_option == SORT_I)
<a name="l00598"></a>00598                 printf(<span class="stringliteral">" %8d"</span>,<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i]);
<a name="l00599"></a>00599             <span class="keywordflow">if</span> (sort_option == <a class="code" href="main_8h.html#f2c5fd4a2157bbaddee5c93c0cbebb2f">SORT_K</a>)
<a name="l00600"></a>00600                 printf(<span class="stringliteral">" %8d"</span>,<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]]);
<a name="l00601"></a>00601         }
<a name="l00602"></a>00602         printf(<span class="stringliteral">"   ]\n"</span>);
<a name="l00603"></a>00603     }
<a name="l00604"></a>00604 
<a name="l00605"></a>00605     <span class="keywordflow">if</span> (vector_mask &amp; <a class="code" href="main_8h.html#fe6b2fe5bc7084afbe5f76d0e4be4d0f">MSK_V</a>)
<a name="l00606"></a>00606     {
<a name="l00607"></a>00607         printf(<span class="stringliteral">" v = [ "</span>);
<a name="l00608"></a>00608         <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00609"></a>00609         {
<a name="l00610"></a>00610             <span class="keywordflow">if</span> (sort_option == SORT_I)
<a name="l00611"></a>00611                 printf(<span class="stringliteral">" %7.4f "</span>,<a class="code" href="main_8c.html#18edff6f6f8cc7071adfd9bc826378ef" title="Wektor bazowych dochodowosci .">v</a>[i]);
<a name="l00612"></a>00612             <span class="keywordflow">if</span> (sort_option == <a class="code" href="main_8h.html#f2c5fd4a2157bbaddee5c93c0cbebb2f">SORT_K</a>)
<a name="l00613"></a>00613                 printf(<span class="stringliteral">" %7.4f "</span>,<a class="code" href="main_8c.html#18edff6f6f8cc7071adfd9bc826378ef" title="Wektor bazowych dochodowosci .">v</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]]);
<a name="l00614"></a>00614         }
<a name="l00615"></a>00615         printf(<span class="stringliteral">"  ]\n"</span>);
<a name="l00616"></a>00616     }
<a name="l00617"></a>00617 
<a name="l00618"></a>00618     <span class="keywordflow">if</span> (vector_mask &amp; <a class="code" href="main_8h.html#b46c763f901435183a60a90c8065135f">MSK_V_</a>)
<a name="l00619"></a>00619     {
<a name="l00620"></a>00620         printf(<span class="stringliteral">" v_= [ "</span>);
<a name="l00621"></a>00621         <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00622"></a>00622         {
<a name="l00623"></a>00623             <span class="keywordflow">if</span> (sort_option == SORT_I)
<a name="l00624"></a>00624                 printf(<span class="stringliteral">" %7.4f "</span>,<a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de" title="Wektor zredukowanych dochodowosci .">v_</a>[i]);
<a name="l00625"></a>00625             <span class="keywordflow">if</span> (sort_option == <a class="code" href="main_8h.html#f2c5fd4a2157bbaddee5c93c0cbebb2f">SORT_K</a>)
<a name="l00626"></a>00626                 printf(<span class="stringliteral">" %7.4f "</span>,<a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de" title="Wektor zredukowanych dochodowosci .">v_</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]]);
<a name="l00627"></a>00627         }
<a name="l00628"></a>00628         printf(<span class="stringliteral">"  ]\n"</span>);
<a name="l00629"></a>00629     }
<a name="l00630"></a>00630 
<a name="l00631"></a>00631     <span class="keywordflow">if</span> (vector_mask &amp; <a class="code" href="main_8h.html#072e387394eca86e5be43efef72251cf">MSK_XR</a>)
<a name="l00632"></a>00632     {
<a name="l00633"></a>00633         printf(<span class="stringliteral">" xr= [ "</span>);
<a name="l00634"></a>00634         <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00635"></a>00635         {
<a name="l00636"></a>00636             <span class="keywordflow">if</span> (sort_option == SORT_I)
<a name="l00637"></a>00637                 printf(<span class="stringliteral">" %7.4f "</span>,<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[i]);
<a name="l00638"></a>00638             <span class="keywordflow">if</span> (sort_option == <a class="code" href="main_8h.html#f2c5fd4a2157bbaddee5c93c0cbebb2f">SORT_K</a>)
<a name="l00639"></a>00639                 printf(<span class="stringliteral">" %7.4f "</span>,<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]]);
<a name="l00640"></a>00640         }
<a name="l00641"></a>00641         printf(<span class="stringliteral">"  ]\n"</span>);
<a name="l00642"></a>00642     }
<a name="l00643"></a>00643 
<a name="l00644"></a>00644 
<a name="l00645"></a>00645     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00646"></a>00646         printf(<span class="stringliteral">"---- printVectors Koniec ----\n"</span>);
<a name="l00647"></a>00647 }
<a name="l00648"></a>00648 
<a name="l00649"></a>00649 
<a name="l00650"></a>00650 <span class="comment">/* ======================================================================</span>
<a name="l00651"></a>00651 <span class="comment"> *  SecureFree</span>
<a name="l00652"></a>00652 <span class="comment"> * ====================================================================== */</span>
<a name="l00657"></a><a class="code" href="main_8c.html#587d85ea68f70d86793ef2e32f75d445">00657</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#587d85ea68f70d86793ef2e32f75d445">SecureFree</a>(<span class="keywordtype">void</span> *pointer)
<a name="l00658"></a>00658 {
<a name="l00659"></a>00659     <span class="keywordflow">if</span> (pointer != NULL)
<a name="l00660"></a>00660         free(pointer);
<a name="l00661"></a>00661     <span class="keywordflow">else</span>
<a name="l00662"></a>00662         printf(<span class="stringliteral">"Zwalnianie pamieci z NULLa!\n"</span>);
<a name="l00663"></a>00663 }
<a name="l00664"></a>00664 
<a name="l00665"></a>00665 
<a name="l00666"></a>00666 <span class="comment">/* ======================================================================</span>
<a name="l00667"></a>00667 <span class="comment"> *  ZwolnijPamiec</span>
<a name="l00668"></a>00668 <span class="comment"> * ====================================================================== */</span>
<a name="l00673"></a><a class="code" href="main_8c.html#01f7419ee78625ea24a0522dbd13917c">00673</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#01f7419ee78625ea24a0522dbd13917c">ZwolnijPamiec</a>()
<a name="l00674"></a>00674 {
<a name="l00675"></a>00675     <a class="code" href="main_8c.html#587d85ea68f70d86793ef2e32f75d445">SecureFree</a>(<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>);
<a name="l00676"></a>00676     <a class="code" href="main_8c.html#587d85ea68f70d86793ef2e32f75d445">SecureFree</a>(<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>);
<a name="l00677"></a>00677     <a class="code" href="main_8c.html#587d85ea68f70d86793ef2e32f75d445">SecureFree</a>(<a class="code" href="main_8c.html#18edff6f6f8cc7071adfd9bc826378ef" title="Wektor bazowych dochodowosci .">v</a>);
<a name="l00678"></a>00678     <a class="code" href="main_8c.html#587d85ea68f70d86793ef2e32f75d445">SecureFree</a>(<a class="code" href="main_8c.html#eb52211fe1c73eb9c9d5568074d3013c" title="Wektor profitow zredukowanych, tj. .">p_</a>);
<a name="l00679"></a>00679     <a class="code" href="main_8c.html#587d85ea68f70d86793ef2e32f75d445">SecureFree</a>(<a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de" title="Wektor zredukowanych dochodowosci .">v_</a>);
<a name="l00680"></a>00680     <a class="code" href="main_8c.html#587d85ea68f70d86793ef2e32f75d445">SecureFree</a>(<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>);
<a name="l00681"></a>00681     <a class="code" href="main_8c.html#587d85ea68f70d86793ef2e32f75d445">SecureFree</a>(<a class="code" href="main_8c.html#4cba98c6387bd12a0acde1fe002efd63" title="Wektor okresla, ktory w kolejnosci malejacej dochodowosci jest i-ty podmiot. .">ki</a>);
<a name="l00682"></a>00682     <a class="code" href="main_8c.html#587d85ea68f70d86793ef2e32f75d445">SecureFree</a>(<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>);
<a name="l00683"></a>00683 
<a name="l00684"></a>00684 }
<a name="l00685"></a>00685 
<a name="l00686"></a>00686 <span class="comment">/* ======================================================================</span>
<a name="l00687"></a>00687 <span class="comment"> *  ZnajdzPoczatkowaLambda2</span>
<a name="l00688"></a>00688 <span class="comment"> * ====================================================================== */</span>
<a name="l00694"></a><a class="code" href="main_8c.html#bb8f4b70c506d3745ffd24352bb42aca">00694</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#bb8f4b70c506d3745ffd24352bb42aca">ZnajdzPoczatkowaLambda2</a>()
<a name="l00695"></a>00695 {
<a name="l00696"></a>00696     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00697"></a>00697     {
<a name="l00698"></a>00698         printf(<span class="stringliteral">"---- ZnajdzPoczatkowaLambda2 ---- \n"</span>);
<a name="l00699"></a>00699         printf(<span class="stringliteral">"Szukamy K-tej najwiekszej wagi p. K = %d.\n"</span>,<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>);
<a name="l00700"></a>00700     }
<a name="l00701"></a>00701     <span class="keywordtype">int</span>* p_sorted = (<span class="keywordtype">int</span> *) malloc(1+ <a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a> * <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
<a name="l00702"></a>00702 
<a name="l00703"></a>00703     <span class="keywordtype">int</span> i;
<a name="l00704"></a>00704     <span class="keywordflow">for</span> (i=1;i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>;i++)
<a name="l00705"></a>00705         p_sorted[i] = <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i];
<a name="l00706"></a>00706     i = 1;
<a name="l00707"></a>00707     <span class="keywordtype">int</span> j;
<a name="l00708"></a>00708     <span class="keywordtype">int</span> p_ind=0;
<a name="l00709"></a>00709     <span class="keywordtype">int</span> maxp,tmp;
<a name="l00710"></a>00710 
<a name="l00711"></a>00711     <span class="comment">// sortowanie babelkowe</span>
<a name="l00712"></a>00712     <span class="keywordflow">while</span> (i&lt;=<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>)
<a name="l00713"></a>00713     {
<a name="l00714"></a>00714         maxp = 0;
<a name="l00715"></a>00715         j = i;
<a name="l00716"></a>00716         <span class="comment">// znalezienie</span>
<a name="l00717"></a>00717         <span class="keywordflow">while</span> (j &lt;= <a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>)
<a name="l00718"></a>00718         {
<a name="l00719"></a>00719             <span class="keywordflow">if</span> (maxp &lt; p_sorted[j])
<a name="l00720"></a>00720             {
<a name="l00721"></a>00721                 maxp = p_sorted[j];
<a name="l00722"></a>00722                 p_ind = j;
<a name="l00723"></a>00723             }
<a name="l00724"></a>00724             <span class="keywordflow">else</span>
<a name="l00725"></a>00725                 j++;
<a name="l00726"></a>00726         }
<a name="l00727"></a>00727         <span class="comment">//zamiana z</span>
<a name="l00728"></a>00728         tmp = p_sorted[i];
<a name="l00729"></a>00729         p_sorted[i] = p_sorted[p_ind];
<a name="l00730"></a>00730         p_sorted[p_ind] = tmp;
<a name="l00731"></a>00731         i++;
<a name="l00732"></a>00732     }
<a name="l00733"></a>00733     <span class="comment">// znaleziono lambda_2</span>
<a name="l00734"></a>00734     <a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a> = p_sorted[<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>];
<a name="l00735"></a>00735 
<a name="l00736"></a>00736     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00737"></a>00737         printf(<span class="stringliteral">"---- ZnajdzPoczatkowaLambda2 koniec. mem:[lambda_2=%f]---- \n"</span>,<a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a>);
<a name="l00738"></a>00738 }
<a name="l00739"></a>00739 
<a name="l00740"></a>00740 <span class="comment">/* ======================================================================</span>
<a name="l00741"></a>00741 <span class="comment"> *  ObliczStanAlokacji</span>
<a name="l00742"></a>00742 <span class="comment"> * ====================================================================== */</span>
<a name="l00753"></a><a class="code" href="main_8c.html#a5c3bae27b8fe935fe170a47139f65c2">00753</a> <span class="keywordtype">double</span> <a class="code" href="main_8c.html#a5c3bae27b8fe935fe170a47139f65c2" title="Na podstawie wartosci wektora  oblicza wartosc alokacji oraz wolny zasob.">ObliczStanAlokacji</a>()
<a name="l00754"></a>00754 {
<a name="l00755"></a>00755     <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> = 0;
<a name="l00756"></a>00756     <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> = <a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>;
<a name="l00757"></a>00757 
<a name="l00758"></a>00758     <span class="keywordtype">int</span> i;
<a name="l00759"></a>00759 
<a name="l00760"></a>00760     <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00761"></a>00761     {
<a name="l00762"></a>00762         <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> += (double)<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i]*<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[i];
<a name="l00763"></a>00763         <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> -= (double)<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i]*<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[i];
<a name="l00764"></a>00764     }
<a name="l00765"></a>00765     <span class="keywordflow">return</span> <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a>;
<a name="l00766"></a>00766 }
<a name="l00767"></a>00767 
<a name="l00768"></a>00768 <span class="comment">/* ======================================================================</span>
<a name="l00769"></a>00769 <span class="comment"> *  AlokujZachlannie</span>
<a name="l00770"></a>00770 <span class="comment"> * ====================================================================== */</span>
<a name="l00780"></a><a class="code" href="main_8c.html#839a6caa67dc71f4f5b8502ae6d3e3f9">00780</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#839a6caa67dc71f4f5b8502ae6d3e3f9" title="Funkcja znajduje rozwiazanie problemu tzw. metoda zachlanna.">AlokujZachlannie</a>()
<a name="l00781"></a>00781 {
<a name="l00782"></a>00782     <a class="code" href="main_8c.html#362a3c1431859c5851d11cf139c74b31">SortujB</a>();
<a name="l00783"></a>00783     <span class="keywordtype">int</span> j = 1;
<a name="l00784"></a>00784 
<a name="l00785"></a>00785     <span class="comment">// poczatkowe czyszczenie zawartosci plecaka</span>
<a name="l00786"></a>00786     <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> = <a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>;
<a name="l00787"></a>00787     <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> = 0;
<a name="l00788"></a>00788     <span class="keywordflow">for</span> (j=1; j&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; j++)
<a name="l00789"></a>00789         <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[j] = 0;
<a name="l00790"></a>00790 
<a name="l00791"></a>00791     j = 1;
<a name="l00792"></a>00792 
<a name="l00793"></a>00793     <span class="keywordflow">while</span> (<a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> &gt;= <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j]] &amp;&amp; j &lt;= <a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>)
<a name="l00794"></a>00794     {
<a name="l00795"></a>00795         <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> -= <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j]];
<a name="l00796"></a>00796         <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> += (double) <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[ik[j]];
<a name="l00797"></a>00797         <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[ik[j]] = 1;
<a name="l00798"></a>00798         j++;
<a name="l00799"></a>00799     }
<a name="l00800"></a>00800 
<a name="l00801"></a>00801     <span class="keywordflow">if</span> (j != <a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>+1)
<a name="l00802"></a>00802     {
<a name="l00803"></a>00803         <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j]] = (double) <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a>/<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[j]];
<a name="l00804"></a>00804         <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> += (double) <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[ik[j]]*<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[ik[j]];
<a name="l00805"></a>00805 
<a name="l00806"></a>00806         <a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a> = j;
<a name="l00807"></a>00807         <a class="code" href="main_8c.html#ba4ddc236971684b95ae11d622e50237" title="Aktualna wartosc C(  ).">aktualneC</a> = <a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>-1 + <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[ik[<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>]];
<a name="l00808"></a>00808         <a class="code" href="main_8c.html#262072a74026166e1c7b6bf6f135791b" title="Indeks elementu granicznego (wg nomenklatury i.">i_s</a> = ik[<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>];
<a name="l00809"></a>00809     }
<a name="l00810"></a>00810 
<a name="l00811"></a>00811     <span class="keywordflow">else</span>
<a name="l00812"></a>00812     {
<a name="l00813"></a>00813         <span class="comment">// przydzielismy zasob WSZYSTKIM elementom</span>
<a name="l00814"></a>00814         <a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a> = <a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>+1;
<a name="l00815"></a>00815         <a class="code" href="main_8c.html#262072a74026166e1c7b6bf6f135791b" title="Indeks elementu granicznego (wg nomenklatury i.">i_s</a> = <a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>+1;
<a name="l00816"></a>00816         <a class="code" href="main_8c.html#ba4ddc236971684b95ae11d622e50237" title="Aktualna wartosc C(  ).">aktualneC</a> = <a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>;
<a name="l00817"></a>00817     }
<a name="l00818"></a>00818 }
<a name="l00819"></a>00819 
<a name="l00820"></a>00820 <span class="comment">/* ======================================================================</span>
<a name="l00821"></a>00821 <span class="comment"> *  AktualizujZredukowaneWagi</span>
<a name="l00822"></a>00822 <span class="comment"> * ====================================================================== */</span>
<a name="l00827"></a><a class="code" href="main_8c.html#e0efa66f476cffdfc64cb39068721c92">00827</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#e0efa66f476cffdfc64cb39068721c92" title="Funkcja aktualizuje wartosci  oraz  w wektorach na podstawie aktualnej wartosci ...">AktualizujZredukowaneWagi</a>()
<a name="l00828"></a>00828 {
<a name="l00829"></a>00829     <span class="keywordtype">int</span> i;
<a name="l00830"></a>00830     <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00831"></a>00831     {
<a name="l00832"></a>00832         <a class="code" href="main_8c.html#eb52211fe1c73eb9c9d5568074d3013c" title="Wektor profitow zredukowanych, tj. .">p_</a>[i] = <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i] - <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>;
<a name="l00833"></a>00833         <a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de" title="Wektor zredukowanych dochodowosci .">v_</a>[i] = (double) <a class="code" href="main_8c.html#eb52211fe1c73eb9c9d5568074d3013c" title="Wektor profitow zredukowanych, tj. .">p_</a>[i]/<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i];
<a name="l00834"></a>00834     }
<a name="l00835"></a>00835 }
<a name="l00836"></a>00836 
<a name="l00837"></a>00837 <span class="comment">/* ======================================================================</span>
<a name="l00838"></a>00838 <span class="comment"> *  C</span>
<a name="l00839"></a>00839 <span class="comment"> * ====================================================================== */</span>
<a name="l00851"></a><a class="code" href="main_8c.html#3d9a7e827f0aea2b3b298ede3ec7427c">00851</a> <span class="keywordtype">double</span> <a class="code" href="main_8c.html#3d9a7e827f0aea2b3b298ede3ec7427c" title="Funkcja obliczajaca C wyznacza sume x-ow (elementow, ktorym przydzielono zasob).">C</a>(<span class="keywordtype">double</span> argLambda)
<a name="l00852"></a>00852 {
<a name="l00853"></a>00853     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00854"></a>00854         printf(<span class="stringliteral">"\nZnajdowanie C(%f)...\n"</span>,argLambda);
<a name="l00855"></a>00855     <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a> = argLambda;
<a name="l00856"></a>00856 
<a name="l00857"></a>00857     <span class="comment">/* aktualizacje wartosci p_ (zredukowanych) i wspolczynnikow dochodowosci v_</span>
<a name="l00858"></a>00858 <span class="comment">     */</span>
<a name="l00859"></a>00859     <a class="code" href="main_8c.html#e0efa66f476cffdfc64cb39068721c92" title="Funkcja aktualizuje wartosci  oraz  w wektorach na podstawie aktualnej wartosci ...">AktualizujZredukowaneWagi</a>();
<a name="l00860"></a>00860     <a class="code" href="main_8c.html#839a6caa67dc71f4f5b8502ae6d3e3f9" title="Funkcja znajduje rozwiazanie problemu tzw. metoda zachlanna.">AlokujZachlannie</a>();
<a name="l00861"></a>00861 
<a name="l00862"></a>00862     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00863"></a>00863     {
<a name="l00864"></a>00864         printf(<span class="stringliteral">"C(%.2f) = %f,\t"</span>,<a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>,<a class="code" href="main_8c.html#ba4ddc236971684b95ae11d622e50237" title="Aktualna wartosc C(  ).">aktualneC</a>);
<a name="l00865"></a>00865         printf(<span class="stringliteral">"s(%.2f) = %d\n\n"</span>,<a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>,<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>);
<a name="l00866"></a>00866     }
<a name="l00867"></a>00867     <span class="keywordflow">return</span> <a class="code" href="main_8c.html#ba4ddc236971684b95ae11d622e50237" title="Aktualna wartosc C(  ).">aktualneC</a>;
<a name="l00868"></a>00868 }
<a name="l00869"></a>00869 
<a name="l00870"></a>00870 <span class="comment">/* ======================================================================</span>
<a name="l00871"></a>00871 <span class="comment"> *  Poprawianie lambda</span>
<a name="l00872"></a>00872 <span class="comment"> * ====================================================================== */</span>
<a name="l00882"></a><a class="code" href="main_8c.html#a8e5877834c7bb319ebb1a912bcc9399">00882</a> <span class="keywordtype">int</span> <a class="code" href="main_8c.html#a8e5877834c7bb319ebb1a912bcc9399" title="Poprawianie lambda w trakcie rozwiazywania relaksacji.">PoprawLambda</a>(<span class="keywordtype">int</span> typPoprawy)
<a name="l00883"></a>00883 {
<a name="l00884"></a>00884 
<a name="l00885"></a>00885     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00886"></a>00886         printf(<span class="stringliteral">"\nFUNKCJA FINDBETTERLAMBDA.------------------------------------\n"</span>);
<a name="l00887"></a>00887     <span class="keywordtype">int</span> k = 1;
<a name="l00888"></a>00888     <span class="keywordtype">int</span>* i_itemsToCheck = ( <span class="keywordtype">int</span> * ) malloc( 1+<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a> * <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ); <span class="comment">//indeksy (pierwotne) elementow do znalezienia min</span>
<a name="l00889"></a>00889 
<a name="l00890"></a>00890     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00891"></a>00891         printf(<span class="stringliteral">"Szukamy "</span>);
<a name="l00892"></a>00892 
<a name="l00893"></a>00893     <span class="keywordflow">if</span> (typPoprawy == <a class="code" href="main_8c.html#090b5d90b0350e728a076aeef5b1184b">ZNAJDZ_MIN_WIEKSZA</a>)
<a name="l00894"></a>00894     { <span class="comment">//min</span>
<a name="l00895"></a>00895         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00896"></a>00896         {
<a name="l00897"></a>00897             printf(<span class="stringliteral">"najmniejszej lambda WIEKSZEJ OD %f\n"</span>,<a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>);
<a name="l00898"></a>00898             <a class="code" href="main_8c.html#644a6088014dbafc3c8055c4801a9a7b">WypiszWektory</a>(<a class="code" href="main_8h.html#58961bee5268baf32d9ca9ac51bcf126">MSK_INDEX</a>|<a class="code" href="main_8h.html#c4c455795b32257010c9be2b845bddce">MSK_P_</a>|<a class="code" href="main_8h.html#4c4b917a9256232b587e9af27900045e">MSK_W</a>,<a class="code" href="main_8h.html#f2c5fd4a2157bbaddee5c93c0cbebb2f">SORT_K</a>);
<a name="l00899"></a>00899             printf(<span class="stringliteral">"Kandydaci do utraty zasobu: { "</span>);
<a name="l00900"></a>00900         }
<a name="l00901"></a>00901         <span class="keywordtype">int</span> jest_element_do_wypadniecia = 0;
<a name="l00902"></a>00902         <span class="keywordflow">while</span> (k&lt;<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>)
<a name="l00903"></a>00903         {
<a name="l00904"></a>00904             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] &lt; <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>]])
<a name="l00905"></a>00905             {
<a name="l00906"></a>00906                 jest_element_do_wypadniecia = 1;
<a name="l00907"></a>00907                 i_itemsToCheck[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] = 1;
<a name="l00908"></a>00908                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00909"></a>00909                     printf(<span class="stringliteral">"%d "</span>,ik[k]);
<a name="l00910"></a>00910             }
<a name="l00911"></a>00911             k++;
<a name="l00912"></a>00912         }
<a name="l00913"></a>00913 
<a name="l00914"></a>00914         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00915"></a>00915         {
<a name="l00916"></a>00916             <span class="keywordflow">if</span> (!jest_element_do_wypadniecia)
<a name="l00917"></a>00917                 printf(<span class="stringliteral">"BRAK "</span>);
<a name="l00918"></a>00918             printf(<span class="stringliteral">"}.\n"</span>);
<a name="l00919"></a>00919         }
<a name="l00920"></a>00920 
<a name="l00921"></a>00921         <span class="keywordtype">int</span> jest_element_do_wpadniecia = 0;
<a name="l00922"></a>00922         k = <a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>+1;
<a name="l00923"></a>00923         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00924"></a>00924             printf(<span class="stringliteral">"Kandydaci do alokacji: { "</span>);
<a name="l00925"></a>00925         <span class="keywordflow">while</span> (k&gt;<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a> &amp;&amp; k &lt;= <a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>)
<a name="l00926"></a>00926         {
<a name="l00927"></a>00927             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] &gt; <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>]])
<a name="l00928"></a>00928             {
<a name="l00929"></a>00929                 jest_element_do_wpadniecia = 1;
<a name="l00930"></a>00930                 i_itemsToCheck[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] = 1;
<a name="l00931"></a>00931                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00932"></a>00932                     printf(<span class="stringliteral">"%d "</span>,ik[k]);
<a name="l00933"></a>00933             }
<a name="l00934"></a>00934             k++;
<a name="l00935"></a>00935         }
<a name="l00936"></a>00936         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00937"></a>00937         {
<a name="l00938"></a>00938             <span class="keywordflow">if</span> (!jest_element_do_wpadniecia)
<a name="l00939"></a>00939                 printf(<span class="stringliteral">"BRAK "</span>);
<a name="l00940"></a>00940             printf(<span class="stringliteral">"}.\n"</span>);
<a name="l00941"></a>00941             printf(<span class="stringliteral">"Miejsce zerowe elementu s-tego = %d.\n"</span>,<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>]]);
<a name="l00942"></a>00942         }
<a name="l00943"></a>00943         i_itemsToCheck[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>]] = 1;
<a name="l00944"></a>00944 
<a name="l00945"></a>00945         <span class="comment">// zanalizowac kiedy taka sytuacja moze miec miejsce</span>
<a name="l00946"></a>00946         <span class="keywordflow">if</span> (!jest_element_do_wpadniecia &amp;&amp; !jest_element_do_wypadniecia)
<a name="l00947"></a>00947         {
<a name="l00948"></a>00948             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00949"></a>00949             {
<a name="l00950"></a>00950                 printf(<span class="stringliteral">"Nie mozna poprawic wg algorytmu, wiec pozostaje %f.\n"</span>,<a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>);
<a name="l00951"></a>00951                 printf(<span class="stringliteral">"Przesuwamy lambde w prawo tak aby pozostawic k najbardziej dochodowych elementow.\n"</span>);
<a name="l00952"></a>00952             }
<a name="l00953"></a>00953             <a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a> = <a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a>;
<a name="l00954"></a>00954             <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a> = <a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a>;
<a name="l00955"></a>00955             <span class="keywordflow">return</span> 0;
<a name="l00956"></a>00956         }
<a name="l00957"></a>00957 
<a name="l00958"></a>00958         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00959"></a>00959             printf(<span class="stringliteral">"Wybieramy minimum z : {"</span>);
<a name="l00960"></a>00960 
<a name="l00961"></a>00961         <span class="keywordtype">double</span> minLambda = 9999;
<a name="l00962"></a>00962         <span class="keywordtype">int</span> minLambdaIndex = 1;
<a name="l00963"></a>00963         <span class="keywordtype">double</span> potencjalnieMinLambda;
<a name="l00964"></a>00964 
<a name="l00965"></a>00965         <span class="keywordtype">int</span> iterator;
<a name="l00966"></a>00966         <span class="keywordflow">for</span> (iterator=1; iterator&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; iterator++)
<a name="l00967"></a>00967         {
<a name="l00968"></a>00968 
<a name="l00969"></a>00969             <span class="keywordflow">if</span> (i_itemsToCheck[iterator] == 1)
<a name="l00970"></a>00970             {
<a name="l00971"></a>00971                 <span class="keywordflow">if</span> (iterator!=ik[<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>])
<a name="l00972"></a>00972                     potencjalnieMinLambda = (double)(<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[iterator]*<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[s]]-<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[ik[s]]*<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[iterator])/(<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[s]]-<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[iterator]);
<a name="l00973"></a>00973                 <span class="keywordflow">else</span>
<a name="l00974"></a>00974                     potencjalnieMinLambda = <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[ik[s]];
<a name="l00975"></a>00975 
<a name="l00976"></a>00976                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00977"></a>00977                     printf(<span class="stringliteral">" %f "</span>,potencjalnieMinLambda);
<a name="l00978"></a>00978 
<a name="l00979"></a>00979                 <span class="keywordflow">if</span> (minLambda &gt; potencjalnieMinLambda)
<a name="l00980"></a>00980                 {
<a name="l00981"></a>00981                     minLambda = potencjalnieMinLambda;
<a name="l00982"></a>00982                     minLambdaIndex = iterator;
<a name="l00983"></a>00983                 }
<a name="l00984"></a>00984             }
<a name="l00985"></a>00985         }
<a name="l00986"></a>00986 
<a name="l00987"></a>00987         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00988"></a>00988         {
<a name="l00989"></a>00989             printf(<span class="stringliteral">" }, czyli min = %f (x%d "</span>,minLambda,minLambdaIndex);
<a name="l00990"></a>00990             <a class="code" href="main_8c.html#4cba98c6387bd12a0acde1fe002efd63" title="Wektor okresla, ktory w kolejnosci malejacej dochodowosci jest i-ty podmiot. .">ki</a>[minLambdaIndex] &lt;= <a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a> ? printf(<span class="stringliteral">" traci zasob)\n"</span>) : printf(<span class="stringliteral">" otrzymuje zasob)\n"</span>);
<a name="l00991"></a>00991             printf(<span class="stringliteral">"\n"</span>);
<a name="l00992"></a>00992         }
<a name="l00993"></a>00993         <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a> = minLambda;
<a name="l00994"></a>00994         <span class="keywordflow">return</span> 0;
<a name="l00995"></a>00995 
<a name="l00996"></a>00996     }
<a name="l00997"></a>00997     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (typPoprawy == <a class="code" href="main_8c.html#edc0d239bfc447fb9dc15e7a96c0a19d">ZNAJDZ_MAX_MNIEJSZA</a>)
<a name="l00998"></a>00998     {
<a name="l00999"></a>00999         <span class="comment">//max</span>
<a name="l01000"></a>01000         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01001"></a>01001         {
<a name="l01002"></a>01002             printf(<span class="stringliteral">"najwiekszej lambda' MNIEJSZEJ OD %f\n"</span>,<a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>);
<a name="l01003"></a>01003             <a class="code" href="main_8c.html#644a6088014dbafc3c8055c4801a9a7b">WypiszWektory</a>(<a class="code" href="main_8h.html#58961bee5268baf32d9ca9ac51bcf126">MSK_INDEX</a>|<a class="code" href="main_8h.html#c4c455795b32257010c9be2b845bddce">MSK_P_</a>|<a class="code" href="main_8h.html#4c4b917a9256232b587e9af27900045e">MSK_W</a>,<a class="code" href="main_8h.html#f2c5fd4a2157bbaddee5c93c0cbebb2f">SORT_K</a>);
<a name="l01004"></a>01004 
<a name="l01005"></a>01005             printf(<span class="stringliteral">"Kandydaci do utraty zasobu: { "</span>);
<a name="l01006"></a>01006         }
<a name="l01007"></a>01007         <span class="keywordflow">while</span> (k&lt;<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>)
<a name="l01008"></a>01008         {
<a name="l01009"></a>01009             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] &gt; <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>]])
<a name="l01010"></a>01010             {
<a name="l01011"></a>01011                 i_itemsToCheck[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] = 1;
<a name="l01012"></a>01012                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01013"></a>01013                     printf(<span class="stringliteral">"%d "</span>,ik[k]);
<a name="l01014"></a>01014             }
<a name="l01015"></a>01015             k++;
<a name="l01016"></a>01016         }
<a name="l01017"></a>01017         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01018"></a>01018             printf(<span class="stringliteral">"}.\n"</span>);
<a name="l01019"></a>01019 
<a name="l01020"></a>01020         k = <a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>+1;
<a name="l01021"></a>01021         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01022"></a>01022             printf(<span class="stringliteral">"Kandydaci do alokacji: { "</span>);
<a name="l01023"></a>01023         <span class="keywordflow">while</span> (k&gt;<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a> &amp;&amp; k &lt;= <a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>)
<a name="l01024"></a>01024         {
<a name="l01025"></a>01025             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] &lt; <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>]])
<a name="l01026"></a>01026             {
<a name="l01027"></a>01027                 i_itemsToCheck[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] = 1;
<a name="l01028"></a>01028                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01029"></a>01029                     printf(<span class="stringliteral">"%d "</span>,ik[k]);
<a name="l01030"></a>01030             }
<a name="l01031"></a>01031             k++;
<a name="l01032"></a>01032         }
<a name="l01033"></a>01033         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01034"></a>01034             printf(<span class="stringliteral">"}\n"</span>);
<a name="l01035"></a>01035 
<a name="l01036"></a>01036         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01037"></a>01037             printf(<span class="stringliteral">"Wybieramy maksimum z : {"</span>);
<a name="l01038"></a>01038 
<a name="l01039"></a>01039         <span class="keywordtype">double</span> maxLambda = -9999;
<a name="l01040"></a>01040         <span class="keywordtype">int</span> maxLambdaIndex = 1;
<a name="l01041"></a>01041         <span class="keywordtype">double</span> potencjalnieMaxLambda;
<a name="l01042"></a>01042 
<a name="l01043"></a>01043         <span class="keywordtype">int</span> iterator;
<a name="l01044"></a>01044         <span class="keywordflow">for</span> (iterator=1; iterator&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; iterator++)
<a name="l01045"></a>01045         {
<a name="l01046"></a>01046 
<a name="l01047"></a>01047             <span class="keywordflow">if</span> (i_itemsToCheck[iterator] == 1)
<a name="l01048"></a>01048             {
<a name="l01049"></a>01049                 potencjalnieMaxLambda = (double)(<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[iterator]*<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>]]-<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>]]*<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[iterator])/(<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>]]-<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[iterator]);
<a name="l01050"></a>01050                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01051"></a>01051                     printf(<span class="stringliteral">" %f "</span>,potencjalnieMaxLambda);
<a name="l01052"></a>01052                 <span class="comment">//znajdowanie maksa</span>
<a name="l01053"></a>01053                 <span class="keywordflow">if</span> (maxLambda &lt; potencjalnieMaxLambda)
<a name="l01054"></a>01054                 {
<a name="l01055"></a>01055                     maxLambda = potencjalnieMaxLambda;
<a name="l01056"></a>01056                     maxLambdaIndex = iterator;
<a name="l01057"></a>01057                 }
<a name="l01058"></a>01058             }
<a name="l01059"></a>01059         }
<a name="l01060"></a>01060         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01061"></a>01061         {
<a name="l01062"></a>01062             printf(<span class="stringliteral">" }, czyli max = %f (x%d "</span>,maxLambda,maxLambdaIndex);
<a name="l01063"></a>01063             <a class="code" href="main_8c.html#4cba98c6387bd12a0acde1fe002efd63" title="Wektor okresla, ktory w kolejnosci malejacej dochodowosci jest i-ty podmiot. .">ki</a>[maxLambdaIndex] &lt; <a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a> ? printf(<span class="stringliteral">" wypada z plecaka)\n"</span>) : printf(<span class="stringliteral">" wpada do plecaka)\n"</span>);
<a name="l01064"></a>01064         }
<a name="l01065"></a>01065         <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a> = maxLambda;
<a name="l01066"></a>01066     }
<a name="l01067"></a>01067 
<a name="l01068"></a>01068     <span class="keywordflow">return</span> 0;
<a name="l01069"></a>01069 }
<a name="l01070"></a>01070 
<a name="l01071"></a>01071 <span class="comment">/* ======================================================================</span>
<a name="l01072"></a>01072 <span class="comment"> *  Relaksacja</span>
<a name="l01073"></a>01073 <span class="comment"> * ====================================================================== */</span>
<a name="l01078"></a><a class="code" href="main_8c.html#cdd4e11b1fc38e16d036b25d02df00f0">01078</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#cdd4e11b1fc38e16d036b25d02df00f0" title="Implementacja rozwiazania zrelaksowanego problemu KP01&amp;lt;=K.">Relaksacja</a>()
<a name="l01079"></a>01079 {
<a name="l01080"></a>01080 
<a name="l01081"></a>01081     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01082"></a>01082         printf(<span class="stringliteral">"\nFUNKCJA RELAKSACJA.------------------------------\n"</span>);
<a name="l01083"></a>01083 
<a name="l01085"></a>01085     <span class="keywordtype">int</span> i,sumaWszystkichWag = 0;
<a name="l01086"></a>01086 
<a name="l01087"></a>01087     <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l01088"></a>01088         sumaWszystkichWag += <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i];
<a name="l01089"></a>01089     <span class="keywordflow">if</span> (sumaWszystkichWag &lt;= <a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>)
<a name="l01090"></a>01090     {
<a name="l01091"></a>01091         printf(<span class="stringliteral">"Mozna przydzielic zasob wszystkim podmiotom (suma zapotrzebowan = %d, ograniczenie = %d)!\n"</span>,sumaWszystkichWag,<a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>);
<a name="l01092"></a>01092         <span class="keywordflow">return</span>;
<a name="l01093"></a>01093     }
<a name="l01094"></a>01094     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01095"></a>01095         printf(<span class="stringliteral">"\nTest 1 (suma wag elementow &gt; c) : OK\t"</span>);
<a name="l01096"></a>01096 
<a name="l01098"></a>01098     <span class="keywordtype">int</span> minWeight = <a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>+1;
<a name="l01099"></a>01099     <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l01100"></a>01100         minWeight = minWeight &lt; <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i] ? minWeight : <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i];
<a name="l01101"></a>01101     <span class="keywordflow">if</span> (minWeight &gt; <a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>)
<a name="l01102"></a>01102     {
<a name="l01103"></a>01103         printf(<span class="stringliteral">"Najmniejsze zapotrzebowanie wieksze niz cala ilosc zasobu !\n"</span>); <span class="comment">//a co jesli K = 1?</span>
<a name="l01104"></a>01104         <span class="keywordflow">return</span>;
<a name="l01105"></a>01105     }
<a name="l01106"></a>01106     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01107"></a>01107         printf(<span class="stringliteral">"\nTest 2 (min w &lt; c) : OK\n\n"</span>);
<a name="l01108"></a>01108 
<a name="l01109"></a>01109     <a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a> = 0;
<a name="l01110"></a>01110     <a class="code" href="main_8c.html#bb8f4b70c506d3745ffd24352bb42aca">ZnajdzPoczatkowaLambda2</a>();
<a name="l01111"></a>01111 
<a name="l01112"></a>01112     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01113"></a>01113         printf(<span class="stringliteral">"lambda_1 = %.4f\t"</span>,<a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a>);
<a name="l01114"></a>01114     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01115"></a>01115         printf(<span class="stringliteral">"lambda_2 = %.4f\n"</span>,<a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a>);
<a name="l01116"></a>01116 
<a name="l01117"></a>01117     <span class="keywordtype">double</span> C_2 = <a class="code" href="main_8c.html#3d9a7e827f0aea2b3b298ede3ec7427c" title="Funkcja obliczajaca C wyznacza sume x-ow (elementow, ktorym przydzielono zasob).">C</a>(<a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a>);
<a name="l01118"></a>01118     <span class="keywordtype">int</span> <a class="code" href="main_8c.html#bc16b71c93276151b863e3c1cde5fc29">s_2</a> = <a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>;
<a name="l01119"></a>01119 
<a name="l01120"></a>01120     <span class="comment">// niepewne</span>
<a name="l01121"></a>01121     <span class="comment">// jezeli C(K-ta najwieksza p) &gt; K,</span>
<a name="l01122"></a>01122     <span class="comment">// to lambda* = lambda_2</span>
<a name="l01123"></a>01123     <span class="comment">// przydzielamy K najbardziej dochodowym podmiotom (wg wag zredukowanych?)</span>
<a name="l01124"></a>01124     <span class="comment">// i koniec</span>
<a name="l01125"></a>01125     <span class="keywordflow">if</span> (C_2 &gt; <a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>)
<a name="l01126"></a>01126     {
<a name="l01127"></a>01127         <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a> = <a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a>;
<a name="l01128"></a>01128         <a class="code" href="main_8c.html#e0efa66f476cffdfc64cb39068721c92" title="Funkcja aktualizuje wartosci  oraz  w wektorach na podstawie aktualnej wartosci ...">AktualizujZredukowaneWagi</a>();
<a name="l01129"></a>01129         <a class="code" href="main_8c.html#362a3c1431859c5851d11cf139c74b31">SortujB</a>();
<a name="l01130"></a>01130         <span class="keywordtype">int</span> k;
<a name="l01131"></a>01131         <span class="keywordflow">for</span> (k=1;k&lt;=<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>;k++)
<a name="l01132"></a>01132             <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] = 1;
<a name="l01133"></a>01133         <span class="keywordflow">for</span> (k=<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>+1;k&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>;k++)
<a name="l01134"></a>01134             <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] = 0;
<a name="l01135"></a>01135     }
<a name="l01136"></a>01136     <span class="keywordflow">else</span>
<a name="l01137"></a>01137     {
<a name="l01138"></a>01138 
<a name="l01139"></a>01139         <span class="keywordtype">double</span> C_1 = <a class="code" href="main_8c.html#3d9a7e827f0aea2b3b298ede3ec7427c" title="Funkcja obliczajaca C wyznacza sume x-ow (elementow, ktorym przydzielono zasob).">C</a>(<a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a>);
<a name="l01140"></a>01140         <span class="keywordtype">int</span> <a class="code" href="main_8c.html#f60379e32a5ed1751e6034c328ca7541">s_1</a> = <a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>;
<a name="l01141"></a>01141 
<a name="l01142"></a>01142         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01143"></a>01143         {
<a name="l01144"></a>01144             printf(<span class="stringliteral">"C(%.2f) = %.4f\t\ts(%.2f) = %d\n"</span>,<a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a>,C_1,<a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a>,s_1);
<a name="l01145"></a>01145             printf(<span class="stringliteral">"C(%.2f) = %.4f\t\ts(%.2f) = %d\n"</span>,<a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a>,C_2,<a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a>,s_2);
<a name="l01146"></a>01146 
<a name="l01147"></a>01147             <span class="comment">/* Kwestia czy pozostawic inicjalna poprawe lambda 1 jest sporna */</span>
<a name="l01148"></a>01148             printf(<span class="stringliteral">"Inicjalna poprawa L1, szukamy najmniejszej lambdy &gt; 0.\n"</span>);
<a name="l01149"></a>01149         }
<a name="l01150"></a>01150         <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a> = <a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a>;
<a name="l01151"></a>01151         <a class="code" href="main_8c.html#362a3c1431859c5851d11cf139c74b31">SortujB</a>();
<a name="l01152"></a>01152         <a class="code" href="main_8c.html#a8e5877834c7bb319ebb1a912bcc9399" title="Poprawianie lambda w trakcie rozwiazywania relaksacji.">PoprawLambda</a>(<a class="code" href="main_8c.html#090b5d90b0350e728a076aeef5b1184b">ZNAJDZ_MIN_WIEKSZA</a>);
<a name="l01153"></a>01153         <a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a> = <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>;
<a name="l01154"></a>01154 
<a name="l01155"></a>01155         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01156"></a>01156             printf(<span class="stringliteral">"\nPONOWNIE FUNKCJA RELAKSACJA.---------------------\n"</span>);
<a name="l01157"></a>01157 
<a name="l01158"></a>01158         <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a> = 0;
<a name="l01159"></a>01159         <span class="keywordflow">while</span> (fabs(<a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a> - <a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a>)&gt;0.01) <span class="comment">// ustawiono 0.01 ze wzgledu iz dokladnosc double jest zawodna</span>
<a name="l01160"></a>01160         {
<a name="l01161"></a>01161             ++<a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a>;
<a name="l01162"></a>01162             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01163"></a>01163                 printf(<span class="stringliteral">"\nITERACJA NR %d."</span>,<a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a>);
<a name="l01164"></a>01164 
<a name="l01165"></a>01165 
<a name="l01166"></a>01166             C_1 = <a class="code" href="main_8c.html#3d9a7e827f0aea2b3b298ede3ec7427c" title="Funkcja obliczajaca C wyznacza sume x-ow (elementow, ktorym przydzielono zasob).">C</a>(<a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a>);
<a name="l01167"></a>01167             s_1 = <a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>;
<a name="l01168"></a>01168             C_2 = <a class="code" href="main_8c.html#3d9a7e827f0aea2b3b298ede3ec7427c" title="Funkcja obliczajaca C wyznacza sume x-ow (elementow, ktorym przydzielono zasob).">C</a>(<a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a>);
<a name="l01169"></a>01169             s_2 = <a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>;
<a name="l01170"></a>01170 
<a name="l01171"></a>01171             <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a> = (<a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a>+<a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a>)/2;
<a name="l01172"></a>01172             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01173"></a>01173                 printf(<span class="stringliteral">"\nlambda_1 = %f\tlambda_2 = %f\tlambda_s = %7.4f\n"</span>,<a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a>,<a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a>,<a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>);
<a name="l01174"></a>01174 
<a name="l01175"></a>01175             <a class="code" href="main_8c.html#3d9a7e827f0aea2b3b298ede3ec7427c" title="Funkcja obliczajaca C wyznacza sume x-ow (elementow, ktorym przydzielono zasob).">C</a>(<a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>);
<a name="l01176"></a>01176             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01177"></a>01177                 printf(<span class="stringliteral">"C(%.2f) = %.4f\t\ts(%.2f) = %d\n"</span>,<a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>,<a class="code" href="main_8c.html#ba4ddc236971684b95ae11d622e50237" title="Aktualna wartosc C(  ).">aktualneC</a>,<a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>,<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>);
<a name="l01178"></a>01178 
<a name="l01179"></a>01179             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#ba4ddc236971684b95ae11d622e50237" title="Aktualna wartosc C(  ).">aktualneC</a> &lt; <a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>)
<a name="l01180"></a>01180             {
<a name="l01181"></a>01181                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01182"></a>01182                     printf(<span class="stringliteral">" &lt; K = %d\nLambda_s zbyt duza, trzeba ja zmniejszyc.\n"</span>,<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>);
<a name="l01183"></a>01183                 <a class="code" href="main_8c.html#a8e5877834c7bb319ebb1a912bcc9399" title="Poprawianie lambda w trakcie rozwiazywania relaksacji.">PoprawLambda</a>(<a class="code" href="main_8c.html#edc0d239bfc447fb9dc15e7a96c0a19d">ZNAJDZ_MAX_MNIEJSZA</a>);
<a name="l01184"></a>01184 
<a name="l01185"></a>01185                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01186"></a>01186                     printf(<span class="stringliteral">"lambda_2 := lambda_s = %7.4f\n"</span>,<a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>);
<a name="l01187"></a>01187                 <a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a> = <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>;
<a name="l01188"></a>01188             }
<a name="l01189"></a>01189             <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#ba4ddc236971684b95ae11d622e50237" title="Aktualna wartosc C(  ).">aktualneC</a> &gt; <a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>)
<a name="l01190"></a>01190             {
<a name="l01191"></a>01191                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01192"></a>01192                     printf(<span class="stringliteral">" &gt; K = %d\nLambda_s zbyt mala, trzeba ja zwiekszyc.\n"</span>,<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>);
<a name="l01193"></a>01193                 <a class="code" href="main_8c.html#a8e5877834c7bb319ebb1a912bcc9399" title="Poprawianie lambda w trakcie rozwiazywania relaksacji.">PoprawLambda</a>(<a class="code" href="main_8c.html#090b5d90b0350e728a076aeef5b1184b">ZNAJDZ_MIN_WIEKSZA</a>);
<a name="l01194"></a>01194 
<a name="l01195"></a>01195                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01196"></a>01196                     printf(<span class="stringliteral">"lambda_1 := lambda_s = %7.4f\n"</span>,<a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>);
<a name="l01197"></a>01197                 <a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a> = <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>;
<a name="l01198"></a>01198             }
<a name="l01199"></a>01199             <span class="keywordflow">else</span>        <span class="comment">// aktualneC == K - kiedy tak moze byc?</span>
<a name="l01200"></a>01200             {
<a name="l01201"></a>01201                 <a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a> = <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>;
<a name="l01202"></a>01202                 <a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a> = <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>;
<a name="l01203"></a>01203                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01204"></a>01204                 {
<a name="l01205"></a>01205                     printf(<span class="stringliteral">"C(lambda_s == %f) == %d == K.\n"</span>,<a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>,<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>);
<a name="l01206"></a>01206                     printf(<span class="stringliteral">"Koniec znajdowania lambda"</span>);
<a name="l01207"></a>01207                 }
<a name="l01208"></a>01208             }
<a name="l01209"></a>01209 
<a name="l01210"></a>01210             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01211"></a>01211                 printf(<span class="stringliteral">"\n"</span>);
<a name="l01212"></a>01212         }
<a name="l01213"></a>01213 
<a name="l01214"></a>01214         <span class="comment">// lambda znaleziona, znajdzmy rozwiazanie relaksacji</span>
<a name="l01215"></a>01215 
<a name="l01216"></a>01216         <a class="code" href="main_8c.html#e0efa66f476cffdfc64cb39068721c92" title="Funkcja aktualizuje wartosci  oraz  w wektorach na podstawie aktualnej wartosci ...">AktualizujZredukowaneWagi</a>();
<a name="l01217"></a>01217         <a class="code" href="main_8c.html#839a6caa67dc71f4f5b8502ae6d3e3f9" title="Funkcja znajduje rozwiazanie problemu tzw. metoda zachlanna.">AlokujZachlannie</a>();
<a name="l01218"></a>01218 
<a name="l01219"></a>01219         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01220"></a>01220         {
<a name="l01221"></a>01221             printf(<span class="stringliteral">"&gt;&gt;&gt; PO ZNALEZIENIU LAMBDA &lt;&lt;&lt;\n"</span>);
<a name="l01222"></a>01222             <a class="code" href="main_8c.html#644a6088014dbafc3c8055c4801a9a7b">WypiszWektory</a>(<a class="code" href="main_8h.html#13b3446f7260cfaa3b9d96fcb961bcc2">MSK_ALL</a>,<a class="code" href="main_8h.html#f2c5fd4a2157bbaddee5c93c0cbebb2f">SORT_K</a>);
<a name="l01223"></a>01223             printf(<span class="stringliteral">"aktualne C %f"</span>,<a class="code" href="main_8c.html#ba4ddc236971684b95ae11d622e50237" title="Aktualna wartosc C(  ).">aktualneC</a>);
<a name="l01224"></a>01224         }
<a name="l01225"></a>01225 
<a name="l01226"></a>01226         <span class="keywordtype">int</span> j;
<a name="l01227"></a>01227         <span class="keywordflow">for</span> (j=<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>+1;j&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>;j++)
<a name="l01228"></a>01228             <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j]] = 0;
<a name="l01229"></a>01229 
<a name="l01230"></a>01230         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#ba4ddc236971684b95ae11d622e50237" title="Aktualna wartosc C(  ).">aktualneC</a> &gt;= <a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>+1)
<a name="l01231"></a>01231         {
<a name="l01232"></a>01232             <a class="code" href="main_8c.html#a5c3bae27b8fe935fe170a47139f65c2" title="Na podstawie wartosci wektora  oblicza wartosc alokacji oraz wolny zasob.">ObliczStanAlokacji</a>();
<a name="l01233"></a>01233             <span class="comment">// bierzemy tylko K najlepszych i do widzenia</span>
<a name="l01234"></a>01234         }
<a name="l01235"></a>01235 
<a name="l01236"></a>01236         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#ba4ddc236971684b95ae11d622e50237" title="Aktualna wartosc C(  ).">aktualneC</a> &gt;= <a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>)
<a name="l01237"></a>01237         {
<a name="l01238"></a>01238             <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>]] = 0;
<a name="l01239"></a>01239             <a class="code" href="main_8c.html#a5c3bae27b8fe935fe170a47139f65c2" title="Na podstawie wartosci wektora  oblicza wartosc alokacji oraz wolny zasob.">ObliczStanAlokacji</a>();
<a name="l01240"></a>01240 
<a name="l01241"></a>01241 
<a name="l01242"></a>01242             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>]] != <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>+1]])
<a name="l01243"></a>01243             {
<a name="l01244"></a>01244                 <span class="keywordtype">double</span> licznik = (double) <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a>-<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>]];
<a name="l01245"></a>01245                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01246"></a>01246                     printf(<span class="stringliteral">"licznik %f\t"</span>,licznik);
<a name="l01247"></a>01247                 <span class="keywordtype">double</span> mianown = (double) <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>+1]]-<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>]];
<a name="l01248"></a>01248                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01249"></a>01249                     printf(<span class="stringliteral">"mianownik %f"</span>,mianown);
<a name="l01250"></a>01250                 <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[ik[<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>+1]] = (double) licznik/mianown;
<a name="l01251"></a>01251                 <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[ik[<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>]] = 1-<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[ik[<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>+1]];
<a name="l01252"></a>01252             }
<a name="l01253"></a>01253             <span class="keywordflow">else</span>
<a name="l01254"></a>01254             {
<a name="l01255"></a>01255                 printf(<span class="stringliteral">"Dziura w kodzie !!!! w_k i w_k+1 rowne, wiec bierzemy dowolny z nich?\n"</span>);
<a name="l01256"></a>01256                 <span class="comment">// w_k i w_k+1 rowne, wiec bierzemy dowolny z nich?</span>
<a name="l01257"></a>01257             }
<a name="l01258"></a>01258 
<a name="l01259"></a>01259             <span class="comment">// korekta, gdy ktorys z elementow (K, K+1) otrzymal</span>
<a name="l01260"></a>01260             <span class="comment">// ujemna wartosc zasobu albo &gt; 1</span>
<a name="l01261"></a>01261             <span class="comment">// korekta ponizej wynikla z problemu (3) opisanego w pliku doc</span>
<a name="l01262"></a>01262             <span class="comment">// i nie jestem jej pewny</span>
<a name="l01263"></a>01263 
<a name="l01264"></a>01264             <span class="keywordflow">if</span> ((<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[ik[<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>+1]]&lt;0)||(<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[ik[<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>]]&lt;0))
<a name="l01265"></a>01265             {
<a name="l01266"></a>01266                 <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[ik[<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>]]=0;
<a name="l01267"></a>01267                 <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[ik[<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>+1]] = 0;
<a name="l01268"></a>01268                 <span class="comment">// wybieramy lepszy</span>
<a name="l01269"></a>01269 
<a name="l01270"></a>01270                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>+1]]&lt;=<a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> &amp;&amp; <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[ik[<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>+1]&gt;=<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[ik[<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>]]])
<a name="l01271"></a>01271                     <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[ik[K]] = 1;
<a name="l01272"></a>01272                 <span class="keywordflow">else</span>
<a name="l01273"></a>01273                     <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[ik[K]] = 0;
<a name="l01274"></a>01274             }
<a name="l01275"></a>01275         }
<a name="l01276"></a>01276         <span class="keywordflow">else</span>
<a name="l01277"></a>01277         {
<a name="l01278"></a>01278             printf(<span class="stringliteral">"Dziura w kodzie !!! jesli C &lt; K to ? \n"</span>); <span class="comment">//jesli C &lt; K to ?</span>
<a name="l01279"></a>01279         }
<a name="l01280"></a>01280     }
<a name="l01281"></a>01281 
<a name="l01282"></a>01282     <a class="code" href="main_8c.html#a5c3bae27b8fe935fe170a47139f65c2" title="Na podstawie wartosci wektora  oblicza wartosc alokacji oraz wolny zasob.">ObliczStanAlokacji</a>();
<a name="l01283"></a>01283 
<a name="l01284"></a>01284     <a class="code" href="main_8c.html#bc046b760068e2015d1f943257ad1c9d">wynikAlokacja</a>[<a class="code" href="main_8c.html#e41c8500c68b74939c9beab3ff16990e">REL</a>] = <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a>;
<a name="l01285"></a>01285     <a class="code" href="main_8c.html#2dc32c866ea1d483256f14beab4f0859">wynikIteracje</a>[<a class="code" href="main_8c.html#e41c8500c68b74939c9beab3ff16990e">REL</a>] = <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a>;
<a name="l01286"></a>01286 
<a name="l01287"></a>01287     <span class="comment">/* ------------- zapis wynikow do pliku - wydzielic w osobnym */</span>
<a name="l01288"></a>01288     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01289"></a>01289     {
<a name="l01290"></a>01290         strcpy(<a class="code" href="main_8c.html#7c91f2a453eee2b8246c3eb270920175">dodatkoweInformacje</a>,<span class="stringliteral">"REL"</span>);
<a name="l01291"></a>01291         <span class="keywordtype">char</span> nazwaPlikuRelaksacjaOut[64];
<a name="l01292"></a>01292         strcpy(nazwaPlikuRelaksacjaOut,<a class="code" href="main_8c.html#e401adba12fa394291ec56e59e8120f4">nazwaPlikuWejsciowego</a>);
<a name="l01293"></a>01293         strcat(nazwaPlikuRelaksacjaOut,<span class="stringliteral">"_RR_out"</span>);
<a name="l01294"></a>01294         <a class="code" href="main_8c.html#7ff0e94f5e3c9337353542d81db57104" title="Generuje pliki wynikowe dla odpowiednich algorytmow.">ZapiszWyniki</a>(nazwaPlikuRelaksacjaOut);
<a name="l01295"></a>01295     }
<a name="l01296"></a>01296 }
<a name="l01297"></a>01297 
<a name="l01298"></a>01298 <span class="comment">/* ======================================================================</span>
<a name="l01299"></a>01299 <span class="comment"> *  ALGORYTM H1</span>
<a name="l01300"></a>01300 <span class="comment"> * ====================================================================== */</span>
<a name="l01305"></a><a class="code" href="main_8c.html#e85b4a7b11917a85362470a56128e990">01305</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#e85b4a7b11917a85362470a56128e990" title="Implementacja algorytmu H1 problemu KP01&amp;lt;=K.">AlgorytmH1</a>()
<a name="l01306"></a>01306 {
<a name="l01307"></a>01307 
<a name="l01308"></a>01308     <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a> = 0;
<a name="l01309"></a>01309     <a class="code" href="main_8c.html#e0efa66f476cffdfc64cb39068721c92" title="Funkcja aktualizuje wartosci  oraz  w wektorach na podstawie aktualnej wartosci ...">AktualizujZredukowaneWagi</a>();
<a name="l01310"></a>01310 
<a name="l01311"></a>01311     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01312"></a>01312         printf(<span class="stringliteral">"ALGORYTM H1----------------------------------\n"</span>);
<a name="l01313"></a>01313 
<a name="l01314"></a>01314     <span class="comment">// AlokujZachlannie wykorzystywany jedynie do znalezienia elementu s-tego</span>
<a name="l01315"></a>01315     <span class="comment">// przypomnienie - element x_s-ty moze byc rowny 0</span>
<a name="l01316"></a>01316     <span class="comment">// definicja x_s - najmniejsze k takie, ze suma k-tych elementow przekracza pojemnosc</span>
<a name="l01317"></a>01317     <a class="code" href="main_8c.html#839a6caa67dc71f4f5b8502ae6d3e3f9" title="Funkcja znajduje rozwiazanie problemu tzw. metoda zachlanna.">AlokujZachlannie</a>();
<a name="l01318"></a>01318     <span class="comment">// tu juz mamy obliczona wartosc 's'</span>
<a name="l01319"></a>01319     <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> = 0;
<a name="l01320"></a>01320     <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a> = 0;
<a name="l01321"></a>01321 
<a name="l01322"></a>01322     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a> &gt;= <a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>)
<a name="l01323"></a>01323     {
<a name="l01324"></a>01324         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01325"></a>01325             printf(<span class="stringliteral">"K &gt;= s, %d &gt;= %d - zatem przydzial standardowy.\n"</span>,<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>,<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>);
<a name="l01326"></a>01326         printf(<span class="stringliteral">"Zalataj dziure (H1)!!\n"</span>);
<a name="l01327"></a>01327     }
<a name="l01328"></a>01328     <span class="keywordflow">else</span>
<a name="l01329"></a>01329     {
<a name="l01330"></a>01330         <span class="keywordtype">int</span> U[<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>];
<a name="l01331"></a>01331         <span class="keywordtype">double</span> sumaU = 0;       <span class="comment">// suma w[u] dla u nalezacych do U</span>
<a name="l01332"></a>01332         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01333"></a>01333             printf(<span class="stringliteral">"k &lt; s, %d &lt; %d, algorytm poprawy start\n"</span>,<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>,<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>);
<a name="l01334"></a>01334         <span class="keywordtype">int</span> i = 1;
<a name="l01335"></a>01335         <span class="keywordtype">int</span> j = <a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>+1;
<a name="l01336"></a>01336         <span class="comment">// alokacja zasobu podmiotom 1..k</span>
<a name="l01337"></a>01337         <span class="comment">// zbior U = Lk</span>
<a name="l01338"></a>01338         <span class="keywordflow">for</span> (i=1;i&lt;=<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>;i++)
<a name="l01339"></a>01339         {
<a name="l01340"></a>01340             U[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]] = 1;
<a name="l01341"></a>01341             <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[ik[i]] = 1;
<a name="l01342"></a>01342             <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> += <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[ik[i]];
<a name="l01343"></a>01343             sumaU += <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[i]];
<a name="l01344"></a>01344         }
<a name="l01345"></a>01345 
<a name="l01346"></a>01346         <span class="comment">// zbior L \ Lk</span>
<a name="l01347"></a>01347         <span class="keywordflow">for</span> (i=<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>+1;i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>;i++)
<a name="l01348"></a>01348         {
<a name="l01349"></a>01349             U[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]] = 0;
<a name="l01350"></a>01350             <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[ik[i]] = 0;
<a name="l01351"></a>01351         }
<a name="l01352"></a>01352 
<a name="l01353"></a>01353         <span class="keywordtype">double</span> delta_z[<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>], delta_ij[<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>];
<a name="l01354"></a>01354         <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a> = 1;
<a name="l01355"></a>01355         <span class="keywordflow">while</span> (j &lt; <a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a> &amp;&amp; sumaU &lt; <a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>)
<a name="l01356"></a>01356         {
<a name="l01357"></a>01357             i = 1;
<a name="l01358"></a>01358             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01359"></a>01359             {
<a name="l01360"></a>01360                 printf(<span class="stringliteral">"\n\nITERACJA %d. j = %d\t"</span>,<a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a>,j);
<a name="l01361"></a>01361                 printf(<span class="stringliteral">"Wartosc alokacji = %f\n"</span>,<a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a>);
<a name="l01362"></a>01362                 printf(<span class="stringliteral">"Zawartosc :\n"</span>);
<a name="l01363"></a>01363                 <a class="code" href="main_8c.html#644a6088014dbafc3c8055c4801a9a7b">WypiszWektory</a>(<a class="code" href="main_8h.html#58961bee5268baf32d9ca9ac51bcf126">MSK_INDEX</a>|<a class="code" href="main_8h.html#e00a20f61164fb74cb09105d2f4348c8">MSK_P</a>|<a class="code" href="main_8h.html#072e387394eca86e5be43efef72251cf">MSK_XR</a>,<a class="code" href="main_8h.html#f2c5fd4a2157bbaddee5c93c0cbebb2f">SORT_K</a>);
<a name="l01364"></a>01364                 printf(<span class="stringliteral">"\nElementy zaalokowane do utraty zasobu na rzecz x%d: "</span>,<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j]);
<a name="l01365"></a>01365             }
<a name="l01366"></a>01366             <span class="keywordtype">int</span> brak=1;
<a name="l01367"></a>01367             <span class="keywordtype">double</span> max_delta =  -1;
<a name="l01368"></a>01368             <span class="keywordtype">int</span> max_delta_index = 1;
<a name="l01369"></a>01369             <span class="keywordflow">while</span> (i &lt;= <a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>)
<a name="l01370"></a>01370             {
<a name="l01371"></a>01371                 <span class="comment">// tylko dla zbioru U z warunkami ''polepszenia rozwiazania''</span>
<a name="l01372"></a>01372                 <span class="keywordflow">if</span> ( (U[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]] == 1) &amp;&amp; (<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]] &lt; <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j]]) &amp;&amp; (<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]] &lt; <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j]]) )
<a name="l01373"></a>01373                 {
<a name="l01374"></a>01374                     <span class="comment">//obliczenie delta_z[i] = pj*delta_ij - pi*xi dla kazdego elementu</span>
<a name="l01375"></a>01375                     brak = 0;
<a name="l01376"></a>01376                     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01377"></a>01377                         printf(<span class="stringliteral">"x%d "</span>,<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]);
<a name="l01378"></a>01378                     delta_ij[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]] = (double) <a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>;
<a name="l01379"></a>01379                     <span class="keywordtype">int</span> u;
<a name="l01380"></a>01380                     <span class="keywordflow">for</span> (u=1; u&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; u++)
<a name="l01381"></a>01381                         <span class="keywordflow">if</span> (U[ik[u]]==1)
<a name="l01382"></a>01382                             delta_ij[ik[i]] -= (double) <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[u]];
<a name="l01383"></a>01383 
<a name="l01384"></a>01384                     delta_ij[ik[i]] += (double) <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[i]];
<a name="l01385"></a>01385                     delta_ij[ik[i]] /= (double) <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[j]];
<a name="l01386"></a>01386 
<a name="l01387"></a>01387                     <span class="keywordflow">if</span> (delta_ij[ik[i]]&gt;1)
<a name="l01388"></a>01388                         delta_ij[ik[i]] = 1;
<a name="l01389"></a>01389 
<a name="l01390"></a>01390                     delta_z[ik[i]] = (double) <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[ik[j]]*delta_ij[ik[i]] - <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[ik[i]]*<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[ik[i]];
<a name="l01391"></a>01391 
<a name="l01392"></a>01392                     <span class="keywordflow">if</span> (delta_z[ik[i]] &gt; max_delta)
<a name="l01393"></a>01393                     {
<a name="l01394"></a>01394                         max_delta = delta_z[ik[i]];
<a name="l01395"></a>01395                         max_delta_index = i;
<a name="l01396"></a>01396                     }
<a name="l01397"></a>01397                 }
<a name="l01398"></a>01398                 i++;
<a name="l01399"></a>01399             }
<a name="l01400"></a>01400             <span class="keywordflow">if</span> (brak)
<a name="l01401"></a>01401             {
<a name="l01402"></a>01402                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01403"></a>01403                     printf(<span class="stringliteral">" BRAK\n"</span>);
<a name="l01404"></a>01404             }
<a name="l01405"></a>01405             <span class="keywordflow">else</span>
<a name="l01406"></a>01406             {
<a name="l01407"></a>01407                 <span class="keywordflow">if</span> (max_delta &gt; 10E-5)
<a name="l01408"></a>01408                 {
<a name="l01409"></a>01409                     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01410"></a>01410                     {
<a name="l01411"></a>01411                         printf(<span class="stringliteral">"\nNajwiekszy przyrost zysku dla elementu x%d delta_z = %f\n"</span>,<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[max_delta_index],max_delta);
<a name="l01412"></a>01412 
<a name="l01413"></a>01413                         printf(<span class="stringliteral">"x%d = %d\t"</span>,<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[max_delta_index],0);
<a name="l01414"></a>01414                         printf(<span class="stringliteral">"x%d = %f\n"</span>,<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j],delta_ij[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[max_delta_index]]);
<a name="l01415"></a>01415                     }
<a name="l01416"></a>01416                     <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> -= <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[max_delta_index]]*<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[max_delta_index]];
<a name="l01417"></a>01417                     <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> += <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[ik[j]]*delta_ij[ik[max_delta_index]];
<a name="l01418"></a>01418 
<a name="l01419"></a>01419                     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01420"></a>01420                         printf(<span class="stringliteral">"Nowa wartosc zaalokowanych zasobow : z = %f "</span>,<a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a>);
<a name="l01421"></a>01421 
<a name="l01422"></a>01422                     <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[ik[max_delta_index]] = 0;
<a name="l01423"></a>01423                     <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[ik[j]] = delta_ij[ik[max_delta_index]];
<a name="l01424"></a>01424 
<a name="l01425"></a>01425                     U[ik[max_delta_index]] = 0;
<a name="l01426"></a>01426                     sumaU -= <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[max_delta_index]];
<a name="l01427"></a>01427                     U[ik[j]] = 1;
<a name="l01428"></a>01428                     sumaU += <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[j]];
<a name="l01429"></a>01429                 }
<a name="l01430"></a>01430             }
<a name="l01431"></a>01431             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01432"></a>01432                 printf(<span class="stringliteral">"suma u = %f"</span>,sumaU);
<a name="l01433"></a>01433 
<a name="l01434"></a>01434             j++;
<a name="l01435"></a>01435             <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a>++;
<a name="l01436"></a>01436         }
<a name="l01437"></a>01437 
<a name="l01438"></a>01438         <a class="code" href="main_8c.html#bc046b760068e2015d1f943257ad1c9d">wynikAlokacja</a>[<a class="code" href="main_8c.html#3e4baeb2553d751ae0c007569655a137">H1</a>] = <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a>;
<a name="l01439"></a>01439         <a class="code" href="main_8c.html#2dc32c866ea1d483256f14beab4f0859">wynikIteracje</a>[<a class="code" href="main_8c.html#3e4baeb2553d751ae0c007569655a137">H1</a>] = <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a>;
<a name="l01440"></a>01440 
<a name="l01441"></a>01441         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01442"></a>01442         {
<a name="l01443"></a>01443             <span class="keywordtype">char</span> nazwaPlikuH1Out[64];
<a name="l01444"></a>01444             strcpy(nazwaPlikuH1Out,<a class="code" href="main_8c.html#e401adba12fa394291ec56e59e8120f4">nazwaPlikuWejsciowego</a>);
<a name="l01445"></a>01445             strcat(nazwaPlikuH1Out,<span class="stringliteral">"_H1_out"</span>);
<a name="l01446"></a>01446             strcpy(<a class="code" href="main_8c.html#7c91f2a453eee2b8246c3eb270920175">dodatkoweInformacje</a>,<span class="stringliteral">"H1"</span>);
<a name="l01447"></a>01447             <a class="code" href="main_8c.html#7ff0e94f5e3c9337353542d81db57104" title="Generuje pliki wynikowe dla odpowiednich algorytmow.">ZapiszWyniki</a>(nazwaPlikuH1Out);
<a name="l01448"></a>01448         }
<a name="l01449"></a>01449     }
<a name="l01450"></a>01450 }
<a name="l01451"></a>01451 
<a name="l01452"></a>01452 <span class="comment">/* ======================================================================</span>
<a name="l01453"></a>01453 <span class="comment"> *  ALGORYTM H2</span>
<a name="l01454"></a>01454 <span class="comment"> * ====================================================================== */</span>
<a name="l01471"></a><a class="code" href="main_8c.html#7afb6457bc15f6a1fea27f461601e850">01471</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#7afb6457bc15f6a1fea27f461601e850" title="Implementacja algorytmu H2 problemu KP01&amp;lt;=K.">AlgorytmH2</a>()
<a name="l01472"></a>01472 {
<a name="l01473"></a>01473 
<a name="l01474"></a>01474 
<a name="l01475"></a>01475     <a class="code" href="main_8c.html#86892a380cb93ebd030dba5a6302be06" title="Inicjalizuje czesc wektorow.">InicjujDane</a>();
<a name="l01476"></a>01476     <a class="code" href="main_8c.html#cdd4e11b1fc38e16d036b25d02df00f0" title="Implementacja rozwiazania zrelaksowanego problemu KP01&amp;lt;=K.">Relaksacja</a>();
<a name="l01477"></a>01477     <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a> = 0;
<a name="l01478"></a>01478 
<a name="l01479"></a>01479     <span class="comment">// jesli co najwyzej K dodatnich x-ow to koniec - zaimplementowac warunek</span>
<a name="l01480"></a>01480     <span class="keywordtype">int</span> ileDodatnichX = 0;
<a name="l01481"></a>01481     <span class="keywordtype">int</span> i;
<a name="l01482"></a>01482     <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l01483"></a>01483         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[i]&gt;0.01)
<a name="l01484"></a>01484             ileDodatnichX++;
<a name="l01485"></a>01485 
<a name="l01486"></a>01486     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01487"></a>01487         printf(<span class="stringliteral">"%d dodatnich x-ow, zatem "</span>,ileDodatnichX);
<a name="l01488"></a>01488 
<a name="l01489"></a>01489     <span class="keywordflow">if</span> (ileDodatnichX &lt;= <a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>)
<a name="l01490"></a>01490     {
<a name="l01491"></a>01491         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01492"></a>01492             printf(<span class="stringliteral">"koniec.\n"</span>);
<a name="l01493"></a>01493     }
<a name="l01494"></a>01494 
<a name="l01495"></a>01495     <span class="keywordflow">else</span> <span class="comment">// liczba dodatnich x-ow &gt; K</span>
<a name="l01496"></a>01496     {
<a name="l01497"></a>01497         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01498"></a>01498             printf(<span class="stringliteral">"algorytm poprawy H2.\n"</span>);
<a name="l01499"></a>01499         <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a> = 1;
<a name="l01500"></a>01500 
<a name="l01501"></a>01501         <span class="comment">// jesli K+1 dodatnich x-ow</span>
<a name="l01502"></a>01502         <span class="keywordtype">int</span> i_a = <a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>];        <span class="comment">//indeksy zgodnie z nomenklatura "i"</span>
<a name="l01503"></a>01503         <span class="keywordtype">int</span> i_b = <a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>+1];
<a name="l01504"></a>01504 
<a name="l01505"></a>01505         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i_a] &gt; <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i_b])
<a name="l01506"></a>01506         {
<a name="l01507"></a>01507             <span class="keywordtype">int</span> tmp;
<a name="l01508"></a>01508             tmp = i_a;
<a name="l01509"></a>01509             i_a = i_b;
<a name="l01510"></a>01510             i_b = tmp;
<a name="l01511"></a>01511         }
<a name="l01512"></a>01512         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01513"></a>01513             printf(<span class="stringliteral">"i_a = %d, i_b = %d\n"</span>,i_a,i_b);
<a name="l01514"></a>01514 
<a name="l01515"></a>01515         <span class="comment">// wiadomo ze w[i_a] &lt;= w[i_b]</span>
<a name="l01516"></a>01516 
<a name="l01517"></a>01517         <span class="keywordtype">double</span> rozw1 = <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> - (<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[i_b]*<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i_b]+<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[i_a]*<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i_a]);       <span class="comment">// rozwiazanie x'</span>
<a name="l01518"></a>01518         <span class="keywordtype">double</span> rozw2 = rozw1;
<a name="l01519"></a>01519 
<a name="l01520"></a>01520         <span class="comment">// rozw1 = J + {a}</span>
<a name="l01521"></a>01521         rozw1 += <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i_a];
<a name="l01522"></a>01522 
<a name="l01523"></a>01523         <span class="comment">// rozw2 = J + czesc {b}</span>
<a name="l01524"></a>01524         <span class="keywordtype">double</span> wolne = <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a>+(<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[i_b]*<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i_b]+<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[i_a]*<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i_a]);
<a name="l01525"></a>01525         <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[i_b] = (double) wolne/<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i_b];
<a name="l01526"></a>01526         rozw2 += xr[i_b]*<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i_b];
<a name="l01527"></a>01527 
<a name="l01528"></a>01528         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01529"></a>01529             printf(<span class="stringliteral">"Lepsze rozwiazanie "</span>);
<a name="l01530"></a>01530 
<a name="l01531"></a>01531         <span class="keywordflow">if</span> (rozw1 &gt; rozw2)
<a name="l01532"></a>01532         {
<a name="l01533"></a>01533             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01534"></a>01534                 printf(<span class="stringliteral">"to x', rowne %f.\n"</span>,rozw1);
<a name="l01535"></a>01535             xr[i_a] = 1;
<a name="l01536"></a>01536             xr[i_b] = 0;
<a name="l01537"></a>01537         }
<a name="l01538"></a>01538         <span class="keywordflow">else</span> <span class="comment">// (rozw1 &lt;= rozw2)</span>
<a name="l01539"></a>01539         {
<a name="l01540"></a>01540             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01541"></a>01541                 printf(<span class="stringliteral">"to x\", rowne %f.\n"</span>,rozw2);
<a name="l01542"></a>01542             xr[i_a] = 0;
<a name="l01543"></a>01543         }
<a name="l01544"></a>01544         <a class="code" href="main_8c.html#a5c3bae27b8fe935fe170a47139f65c2" title="Na podstawie wartosci wektora  oblicza wartosc alokacji oraz wolny zasob.">ObliczStanAlokacji</a>();
<a name="l01545"></a>01545     }
<a name="l01546"></a>01546 
<a name="l01547"></a>01547     <a class="code" href="main_8c.html#bc046b760068e2015d1f943257ad1c9d">wynikAlokacja</a>[<a class="code" href="main_8c.html#b5e8a97982062958fb8f58a428df09ee">H2</a>] = <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a>;
<a name="l01548"></a>01548     <a class="code" href="main_8c.html#2dc32c866ea1d483256f14beab4f0859">wynikIteracje</a>[<a class="code" href="main_8c.html#b5e8a97982062958fb8f58a428df09ee">H2</a>] = <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a>;
<a name="l01549"></a>01549 
<a name="l01550"></a>01550     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01551"></a>01551     {
<a name="l01552"></a>01552         strcpy(<a class="code" href="main_8c.html#7c91f2a453eee2b8246c3eb270920175">dodatkoweInformacje</a>,<span class="stringliteral">"H2"</span>);
<a name="l01553"></a>01553         <span class="keywordtype">char</span> nazwaPlikuH2Out[64];
<a name="l01554"></a>01554         strcpy(nazwaPlikuH2Out,<a class="code" href="main_8c.html#e401adba12fa394291ec56e59e8120f4">nazwaPlikuWejsciowego</a>);
<a name="l01555"></a>01555         strcat(nazwaPlikuH2Out,<span class="stringliteral">"_H2_out"</span>);
<a name="l01556"></a>01556         <a class="code" href="main_8c.html#7ff0e94f5e3c9337353542d81db57104" title="Generuje pliki wynikowe dla odpowiednich algorytmow.">ZapiszWyniki</a>(nazwaPlikuH2Out);
<a name="l01557"></a>01557     }
<a name="l01558"></a>01558 }
<a name="l01559"></a>01559 
<a name="l01560"></a>01560 <span class="comment">/* ======================================================================</span>
<a name="l01561"></a>01561 <span class="comment"> *  ALGORYTM H2 PRIM</span>
<a name="l01562"></a>01562 <span class="comment"> * ====================================================================== */</span>
<a name="l01570"></a><a class="code" href="main_8c.html#c7f7228e325a7bc232d8940ccec07979">01570</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#c7f7228e325a7bc232d8940ccec07979" title="Implementacja algorytmu H2&amp;#39; problemu KP01&amp;lt;=K.">AlgorytmH2Prim</a>()
<a name="l01571"></a>01571 {
<a name="l01572"></a>01572     strcpy(<a class="code" href="main_8c.html#7c91f2a453eee2b8246c3eb270920175">dodatkoweInformacje</a>,<span class="stringliteral">"H2\'"</span>);
<a name="l01573"></a>01573 
<a name="l01574"></a>01574     <a class="code" href="main_8c.html#86892a380cb93ebd030dba5a6302be06" title="Inicjalizuje czesc wektorow.">InicjujDane</a>();
<a name="l01575"></a>01575     <a class="code" href="main_8c.html#cdd4e11b1fc38e16d036b25d02df00f0" title="Implementacja rozwiazania zrelaksowanego problemu KP01&amp;lt;=K.">Relaksacja</a>();
<a name="l01576"></a>01576     <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a> = 0;
<a name="l01577"></a>01577 
<a name="l01578"></a>01578     <span class="comment">// jesli co najwyzej K dodatnich x-ow to koniec - zaimplementowac warunek</span>
<a name="l01579"></a>01579     <span class="keywordtype">int</span> ileDodatnichX = 0;
<a name="l01580"></a>01580     <span class="keywordtype">int</span> i;
<a name="l01581"></a>01581 
<a name="l01582"></a>01582     <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l01583"></a>01583     {
<a name="l01584"></a>01584         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[i]&gt;0.01)
<a name="l01585"></a>01585             ileDodatnichX++;
<a name="l01586"></a>01586         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[i]&lt;1)
<a name="l01587"></a>01587         {
<a name="l01588"></a>01588             <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[i] = 0;
<a name="l01589"></a>01589         }
<a name="l01590"></a>01590     }
<a name="l01591"></a>01591 
<a name="l01592"></a>01592     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01593"></a>01593 
<a name="l01594"></a>01594         printf(<span class="stringliteral">"%d dodatnich x-ow, zatem "</span>,ileDodatnichX);
<a name="l01595"></a>01595 
<a name="l01596"></a>01596     <span class="keywordflow">if</span> (ileDodatnichX &lt;= <a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>)
<a name="l01597"></a>01597     {
<a name="l01598"></a>01598         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01599"></a>01599             printf(<span class="stringliteral">"koniec.\n"</span>);
<a name="l01600"></a>01600     }
<a name="l01601"></a>01601     <span class="keywordflow">else</span> <span class="comment">// liczba dodatnich x-ow &gt; K</span>
<a name="l01602"></a>01602     {
<a name="l01603"></a>01603         printf(<span class="stringliteral">"algorytm poprawy H2'.\n"</span>);
<a name="l01604"></a>01604         <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a> = 1;
<a name="l01605"></a>01605         <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l01606"></a>01606             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[i]&lt;1)
<a name="l01607"></a>01607                 <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[i] = 0;
<a name="l01608"></a>01608         <a class="code" href="main_8c.html#a5c3bae27b8fe935fe170a47139f65c2" title="Na podstawie wartosci wektora  oblicza wartosc alokacji oraz wolny zasob.">ObliczStanAlokacji</a>();
<a name="l01609"></a>01609 
<a name="l01610"></a>01610         <span class="keywordtype">double</span> najwiekszyZysk = -1;
<a name="l01611"></a>01611         <span class="keywordtype">int</span> i_najlepszy;
<a name="l01612"></a>01612 
<a name="l01613"></a>01613         <span class="keywordflow">for</span> (i=1;i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>;i++)
<a name="l01614"></a>01614         {
<a name="l01615"></a>01615             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[i] == 0)
<a name="l01616"></a>01616             {
<a name="l01617"></a>01617                 <span class="keywordtype">double</span> zysk_i;
<a name="l01618"></a>01618                 <span class="keywordtype">double</span> x_i;
<a name="l01619"></a>01619 
<a name="l01620"></a>01620                 x_i = <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i] &gt; <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> ? <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a>/<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i] : 1;
<a name="l01621"></a>01621                 zysk_i = x_i * <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i];
<a name="l01622"></a>01622                 <span class="keywordflow">if</span> (zysk_i &gt; najwiekszyZysk)
<a name="l01623"></a>01623                 {
<a name="l01624"></a>01624                     najwiekszyZysk = zysk_i;
<a name="l01625"></a>01625                     i_najlepszy = i;
<a name="l01626"></a>01626                 }
<a name="l01627"></a>01627             }
<a name="l01628"></a>01628         }
<a name="l01629"></a>01629         printf(<span class="stringliteral">"Najlepszy zysk = %f dla x%d.\n"</span>,najwiekszyZysk,i_najlepszy);
<a name="l01630"></a>01630         <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[i_najlepszy] = 1;
<a name="l01631"></a>01631 
<a name="l01632"></a>01632         <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a> = 0;
<a name="l01633"></a>01633         <a class="code" href="main_8c.html#362a3c1431859c5851d11cf139c74b31">SortujB</a>();
<a name="l01634"></a>01634 
<a name="l01635"></a>01635         <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> = <a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>;
<a name="l01636"></a>01636         <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> = 0;
<a name="l01637"></a>01637 
<a name="l01638"></a>01638         <span class="keywordtype">int</span> j = 1;
<a name="l01639"></a>01639 
<a name="l01640"></a>01640         <span class="keywordflow">while</span> (<a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> &gt; 0 &amp;&amp; j &lt;= <a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>)
<a name="l01641"></a>01641         {
<a name="l01642"></a>01642             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j]]&gt;0)
<a name="l01643"></a>01643             {   <span class="comment">// tylko dla zbioru J + {i}</span>
<a name="l01644"></a>01644                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> &gt;= <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j]])
<a name="l01645"></a>01645                 {
<a name="l01646"></a>01646                     <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> -= <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j]];
<a name="l01647"></a>01647                     <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> += (double) <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[ik[j]];
<a name="l01648"></a>01648                     <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[ik[j]] = 1;
<a name="l01649"></a>01649                 }
<a name="l01650"></a>01650                 <span class="keywordflow">else</span>
<a name="l01651"></a>01651                 {
<a name="l01652"></a>01652                     <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j]] = <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a>/<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[j]];
<a name="l01653"></a>01653                     <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> += (double) <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[ik[j]]*<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[ik[j]];
<a name="l01654"></a>01654                     <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> = 0;
<a name="l01655"></a>01655                 }
<a name="l01656"></a>01656             }
<a name="l01657"></a>01657             j++;
<a name="l01658"></a>01658         }
<a name="l01659"></a>01659     }
<a name="l01660"></a>01660 
<a name="l01661"></a>01661     <a class="code" href="main_8c.html#bc046b760068e2015d1f943257ad1c9d">wynikAlokacja</a>[<a class="code" href="main_8c.html#e3ea6c504e916b75b4e44abeffdb8477">H2P</a>] = <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a>;
<a name="l01662"></a>01662     <a class="code" href="main_8c.html#2dc32c866ea1d483256f14beab4f0859">wynikIteracje</a>[<a class="code" href="main_8c.html#e3ea6c504e916b75b4e44abeffdb8477">H2P</a>] = <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a>;
<a name="l01663"></a>01663 
<a name="l01664"></a>01664     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01665"></a>01665     {
<a name="l01666"></a>01666         <span class="keywordtype">char</span> nazwaPlikuH2pOut[64];
<a name="l01667"></a>01667         strcpy(nazwaPlikuH2pOut,<a class="code" href="main_8c.html#e401adba12fa394291ec56e59e8120f4">nazwaPlikuWejsciowego</a>);
<a name="l01668"></a>01668         strcat(nazwaPlikuH2pOut,<span class="stringliteral">"_H2p_out"</span>);
<a name="l01669"></a>01669         <a class="code" href="main_8c.html#7ff0e94f5e3c9337353542d81db57104" title="Generuje pliki wynikowe dla odpowiednich algorytmow.">ZapiszWyniki</a>(nazwaPlikuH2pOut);
<a name="l01670"></a>01670     }
<a name="l01671"></a>01671 }
<a name="l01672"></a>01672 
<a name="l01673"></a>01673 <span class="comment">/* ======================================================================</span>
<a name="l01674"></a>01674 <span class="comment"> *  ALGORYTM H2 BIS</span>
<a name="l01675"></a>01675 <span class="comment"> * ====================================================================== */</span>
<a name="l01685"></a><a class="code" href="main_8c.html#779e9c536e6db05731f94e52eabadfdd">01685</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#779e9c536e6db05731f94e52eabadfdd" title="Implementacja algorytmu H2 BIS problemu KP01&amp;lt;=K.">AlgorytmH2Bis</a>()
<a name="l01686"></a>01686 {
<a name="l01687"></a>01687 
<a name="l01688"></a>01688     <a class="code" href="main_8c.html#86892a380cb93ebd030dba5a6302be06" title="Inicjalizuje czesc wektorow.">InicjujDane</a>();
<a name="l01689"></a>01689     <a class="code" href="main_8c.html#cdd4e11b1fc38e16d036b25d02df00f0" title="Implementacja rozwiazania zrelaksowanego problemu KP01&amp;lt;=K.">Relaksacja</a>();
<a name="l01690"></a>01690     <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a> = 0;
<a name="l01691"></a>01691     <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a> = 0;
<a name="l01692"></a>01692 
<a name="l01693"></a>01693     <span class="comment">// jesli co najwyzej K dodatnich x-ow to koniec - zaimplementowac warunek</span>
<a name="l01694"></a>01694     <span class="keywordtype">int</span> ileDodatnichX = 0;
<a name="l01695"></a>01695     <span class="keywordtype">int</span> i;
<a name="l01696"></a>01696     <span class="keywordtype">int</span> L[<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>];
<a name="l01697"></a>01697 
<a name="l01698"></a>01698     <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l01699"></a>01699     {
<a name="l01700"></a>01700         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie.">xr</a>[i]&gt;10e-6)
<a name="l01701"></a>01701         {
<a name="l01702"></a>01702             ileDodatnichX++;
<a name="l01703"></a>01703             L[i] = 1;
<a name="l01704"></a>01704         }
<a name="l01705"></a>01705         <span class="keywordflow">else</span>
<a name="l01706"></a>01706             L[i] = 0;
<a name="l01707"></a>01707     }
<a name="l01708"></a>01708 
<a name="l01709"></a>01709     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01710"></a>01710         printf(<span class="stringliteral">"%d dodatnich x-ow, zatem "</span>,ileDodatnichX);
<a name="l01711"></a>01711 
<a name="l01712"></a>01712     <span class="keywordflow">if</span> (ileDodatnichX &lt;= <a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>)
<a name="l01713"></a>01713     {
<a name="l01714"></a>01714         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01715"></a>01715             printf(<span class="stringliteral">"koniec.\n"</span>);
<a name="l01716"></a>01716 
<a name="l01717"></a>01717     }
<a name="l01718"></a>01718 
<a name="l01719"></a>01719     <span class="keywordflow">else</span> <span class="comment">// liczba dodatnich x-ow &gt; K</span>
<a name="l01720"></a>01720     {
<a name="l01721"></a>01721         printf(<span class="stringliteral">"algorytm poprawy H2\".\n"</span>);
<a name="l01722"></a>01722         <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a> = 1;
<a name="l01723"></a>01723         <span class="keywordtype">int</span> j;
<a name="l01724"></a>01724 
<a name="l01725"></a>01725         <span class="keywordtype">double</span> najlepszyPrzydzial = 0;
<a name="l01726"></a>01726         <span class="comment">// int ktoryUsunac = 0;</span>
<a name="l01727"></a>01727         <a class="code" href="main_8c.html#362a3c1431859c5851d11cf139c74b31">SortujB</a>();
<a name="l01728"></a>01728 
<a name="l01729"></a>01729         <span class="keywordflow">for</span> (j=1; j&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; j++) <span class="comment">// dla kazdego j nalezacego do L</span>
<a name="l01730"></a>01730             <span class="keywordflow">if</span> (L[j]==1)
<a name="l01731"></a>01731             {
<a name="l01732"></a>01732                 L[j] = 0;
<a name="l01733"></a>01733 
<a name="l01734"></a>01734                 <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> = <a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>;
<a name="l01735"></a>01735                 <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> = 0;
<a name="l01736"></a>01736                 <span class="keywordtype">int</span> k=0;
<a name="l01737"></a>01737                 <span class="keywordflow">while</span> (k&lt;<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>)
<a name="l01738"></a>01738                 {
<a name="l01739"></a>01739                     k++;
<a name="l01740"></a>01740                     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] &lt;= <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> &amp;&amp; L[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] == 1)
<a name="l01741"></a>01741                     {
<a name="l01742"></a>01742                         <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> -= <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]];
<a name="l01743"></a>01743                         <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> += <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[ik[k]];
<a name="l01744"></a>01744                         <span class="comment">//printf("bez %d alokacja w calosci %d\n",j,ik[k]);</span>
<a name="l01745"></a>01745                     }
<a name="l01746"></a>01746                     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] &gt; <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> &amp;&amp; L[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] == 1)
<a name="l01747"></a>01747                     {
<a name="l01748"></a>01748                         <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> += <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]]*(<a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a>/<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]]);
<a name="l01749"></a>01749                         <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> = 0;
<a name="l01750"></a>01750                         <span class="comment">//printf("bez %d alokacja czesciowa %d\n",j,ik[k]);</span>
<a name="l01751"></a>01751                         <span class="keywordflow">break</span>;
<a name="l01752"></a>01752                     }
<a name="l01753"></a>01753                     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (L[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]]==0)
<a name="l01754"></a>01754                         <span class="keywordflow">continue</span>;
<a name="l01755"></a>01755                 }
<a name="l01756"></a>01756                 printf(<span class="stringliteral">"alokacja bez %d elementu rowna %f\n"</span>,j,<a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a>);
<a name="l01757"></a>01757                 najlepszyPrzydzial = <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> &gt; najlepszyPrzydzial ? <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> : najlepszyPrzydzial;
<a name="l01758"></a>01758                 L[j] = 1;
<a name="l01759"></a>01759             }
<a name="l01760"></a>01760         <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> = najlepszyPrzydzial;
<a name="l01761"></a>01761     }
<a name="l01762"></a>01762 
<a name="l01763"></a>01763     <a class="code" href="main_8c.html#bc046b760068e2015d1f943257ad1c9d">wynikAlokacja</a>[<a class="code" href="main_8c.html#13ba4f47dcd4f3e4a0dca6330c1916f2">H2B</a>] = <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a>;
<a name="l01764"></a>01764     <a class="code" href="main_8c.html#2dc32c866ea1d483256f14beab4f0859">wynikIteracje</a>[<a class="code" href="main_8c.html#13ba4f47dcd4f3e4a0dca6330c1916f2">H2B</a>] = <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a>;
<a name="l01765"></a>01765 
<a name="l01766"></a>01766     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01767"></a>01767     {
<a name="l01768"></a>01768         <span class="keywordtype">char</span> nazwaPlikuH2bisOut[64];
<a name="l01769"></a>01769         strcpy(nazwaPlikuH2bisOut,<a class="code" href="main_8c.html#e401adba12fa394291ec56e59e8120f4">nazwaPlikuWejsciowego</a>);
<a name="l01770"></a>01770         strcat(nazwaPlikuH2bisOut,<span class="stringliteral">"_H2b_out"</span>);
<a name="l01771"></a>01771         strcpy(<a class="code" href="main_8c.html#7c91f2a453eee2b8246c3eb270920175">dodatkoweInformacje</a>,<span class="stringliteral">"H2\""</span>);
<a name="l01772"></a>01772         <a class="code" href="main_8c.html#7ff0e94f5e3c9337353542d81db57104" title="Generuje pliki wynikowe dla odpowiednich algorytmow.">ZapiszWyniki</a>(nazwaPlikuH2bisOut);
<a name="l01773"></a>01773     }
<a name="l01774"></a>01774 }
<a name="l01775"></a>01775 
<a name="l01776"></a>01776 
<a name="l01777"></a>01777 <span class="comment">/* ======================================================================</span>
<a name="l01778"></a>01778 <span class="comment"> *  GLPK_R_D</span>
<a name="l01779"></a>01779 <span class="comment"> * ====================================================================== */</span>
<a name="l01844"></a><a class="code" href="main_8c.html#93e8ae2f06f58ce7bbc167f83da651f9">01844</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#93e8ae2f06f58ce7bbc167f83da651f9" title="Umozliwia rozwiazanie problemu przez zewnetrzny solver (GLPK).">GLPK_R_D</a>()
<a name="l01845"></a>01845 {
<a name="l01846"></a>01846     <span class="keywordtype">char</span> nazwaPlikuDanychGLPK[64];
<a name="l01847"></a>01847     strcpy(nazwaPlikuDanychGLPK,<a class="code" href="main_8c.html#e401adba12fa394291ec56e59e8120f4">nazwaPlikuWejsciowego</a>);
<a name="l01848"></a>01848     strcat(nazwaPlikuDanychGLPK,<span class="stringliteral">"_GLPK_dat"</span>);
<a name="l01849"></a>01849 
<a name="l01850"></a>01850     FILE *plikDanychGLPK;
<a name="l01851"></a>01851     <span class="keywordflow">if</span> (((plikDanychGLPK=fopen(nazwaPlikuDanychGLPK, <span class="stringliteral">"w"</span>))==NULL))
<a name="l01852"></a>01852     {
<a name="l01853"></a>01853         printf(<span class="stringliteral">"Nie mozna otworzyc pliku wyjsciowego do zapisu modelu GMPL.\n"</span>);
<a name="l01854"></a>01854         exit(1);
<a name="l01855"></a>01855     }
<a name="l01856"></a>01856     <span class="keywordflow">else</span>
<a name="l01857"></a>01857         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01858"></a>01858             printf(<span class="stringliteral">"\n\nOtwarto plik do zapisu danych modelu GMPL.\n"</span>);
<a name="l01859"></a>01859 
<a name="l01860"></a>01860 
<a name="l01861"></a>01861     <span class="comment">/* ZAPIS DANYCH W FORMACIE GMPL */</span>
<a name="l01862"></a>01862     fprintf(plikDanychGLPK,<span class="stringliteral">"data;\n"</span>);
<a name="l01863"></a>01863     fprintf(plikDanychGLPK,<span class="stringliteral">"param N := %d ;\n"</span>,<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>);
<a name="l01864"></a>01864     fprintf(plikDanychGLPK,<span class="stringliteral">"param K := %d ;\n"</span>,<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>);
<a name="l01865"></a>01865     fprintf(plikDanychGLPK,<span class="stringliteral">"param c := %d ;\n\n"</span>,<a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>);
<a name="l01866"></a>01866 
<a name="l01867"></a>01867     fprintf(plikDanychGLPK,<span class="stringliteral">"param p := \n"</span>);
<a name="l01868"></a>01868     <span class="keywordtype">int</span> i;
<a name="l01869"></a>01869     <span class="keywordflow">for</span> (i=1;i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>;i++)
<a name="l01870"></a>01870     {
<a name="l01871"></a>01871         fprintf(plikDanychGLPK,<span class="stringliteral">"\n%d\t%d"</span>,i,<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i]);
<a name="l01872"></a>01872     }
<a name="l01873"></a>01873     fprintf(plikDanychGLPK,<span class="stringliteral">";\n\n"</span>);
<a name="l01874"></a>01874 
<a name="l01875"></a>01875     fprintf(plikDanychGLPK,<span class="stringliteral">"param w := \n"</span>);
<a name="l01876"></a>01876     <span class="keywordflow">for</span> (i=1;i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>;i++)
<a name="l01877"></a>01877     {
<a name="l01878"></a>01878         fprintf(plikDanychGLPK,<span class="stringliteral">"\n%d\t%d"</span>,i,<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i]);
<a name="l01879"></a>01879     }
<a name="l01880"></a>01880     fprintf(plikDanychGLPK,<span class="stringliteral">";\nend;\n"</span>);
<a name="l01881"></a>01881     fclose(plikDanychGLPK);
<a name="l01882"></a>01882 
<a name="l01883"></a>01883     <span class="comment">/* UWORZENIE MODELU DANYCH - ZADANIE ZRELAKSOWANE */</span>
<a name="l01884"></a>01884     <span class="keywordtype">char</span> nazwaPlikuModeluGLPK_R[256];
<a name="l01885"></a>01885     tmpnam(nazwaPlikuModeluGLPK_R);
<a name="l01886"></a>01886     strcat(nazwaPlikuModeluGLPK_R,<span class="stringliteral">"_R.mod"</span>);
<a name="l01887"></a>01887 
<a name="l01888"></a>01888     FILE * KP01_R_model = fopen(nazwaPlikuModeluGLPK_R,<span class="stringliteral">"w"</span>);
<a name="l01889"></a>01889     <span class="keywordflow">if</span> (KP01_R_model==NULL)
<a name="l01890"></a>01890     {
<a name="l01891"></a>01891         printf(<span class="stringliteral">"Blad, nie mozna utworzyc tymczasowego pliku do zapisu modelu GLPK!\n"</span>);
<a name="l01892"></a>01892         <span class="keywordflow">return</span>;
<a name="l01893"></a>01893     }
<a name="l01894"></a>01894     fprintf(KP01_R_model,<span class="stringliteral">"%s"</span>,<a class="code" href="main_8h.html#689c7814b58c9ff6a60412016bb1ab9f">KP01_R</a>);
<a name="l01895"></a>01895     fclose(KP01_R_model);
<a name="l01896"></a>01896 
<a name="l01897"></a>01897     <span class="comment">/* Plik LP wygenerowano. Rozwiazujemy problem zrelaksowany.</span>
<a name="l01898"></a>01898 <span class="comment">     * Warunek - dostep do glpsol.exe w zmiennej srodowiskowej PATH.</span>
<a name="l01899"></a>01899 <span class="comment">     * W srodowisku UNIX/Linux analogicznie nalezy zmienic ponizsza komende z glpsol.exe na glpsol */</span>
<a name="l01900"></a>01900     <span class="keywordtype">char</span> wywolanieGLPSOL[128];
<a name="l01901"></a>01901     <span class="keywordtype">char</span> nazwaPlikuWyjsciowegoGLPK_R_out[256],nazwaPlikuWyjsciowegoGLPK_R_log[256];
<a name="l01902"></a>01902 
<a name="l01903"></a>01903     tmpnam(nazwaPlikuWyjsciowegoGLPK_R_out);
<a name="l01904"></a>01904     strcat(nazwaPlikuWyjsciowegoGLPK_R_out,<span class="stringliteral">"_R.out"</span>);
<a name="l01905"></a>01905 
<a name="l01906"></a>01906     tmpnam(nazwaPlikuWyjsciowegoGLPK_R_log);
<a name="l01907"></a>01907     strcat(nazwaPlikuWyjsciowegoGLPK_R_log,<span class="stringliteral">"_R.log"</span>);
<a name="l01908"></a>01908 
<a name="l01909"></a>01909     sprintf(wywolanieGLPSOL,<span class="stringliteral">"glpsol.exe -d %s -m %s -w %s --log %s"</span>,nazwaPlikuDanychGLPK,nazwaPlikuModeluGLPK_R,nazwaPlikuWyjsciowegoGLPK_R_out,nazwaPlikuWyjsciowegoGLPK_R_log);
<a name="l01910"></a>01910     <span class="keywordtype">double</span> wynik = -1;
<a name="l01911"></a>01911     <a class="code" href="main_8c.html#e9284b236f128677657631ae56843cae" title="Funkcja wstrzymuje dzialanie programu na okreslona liczbe sekund.">CzasStart</a>();
<a name="l01912"></a>01912     system(wywolanieGLPSOL);
<a name="l01913"></a>01913     <a class="code" href="main_8c.html#2cc2c7e7811c4a88e4dc3ee60b801508">CzasStop</a>();
<a name="l01914"></a>01914 
<a name="l01915"></a>01915     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>!=1)
<a name="l01916"></a>01916         <span class="keyword">remove</span>(nazwaPlikuModeluGLPK_R);
<a name="l01917"></a>01917 
<a name="l01918"></a>01918     <span class="comment">/* Parse'owanie pliku wyjsciowego zadania zrelaksowanego */</span>
<a name="l01919"></a>01919     <span class="keywordtype">char</span> tmp[128];
<a name="l01920"></a>01920     FILE * GLPK_R_Out = fopen(nazwaPlikuWyjsciowegoGLPK_R_out,<span class="stringliteral">"a+"</span>);
<a name="l01921"></a>01921     fgets(tmp,128,GLPK_R_Out);
<a name="l01922"></a>01922     fgets(tmp,128,GLPK_R_Out);
<a name="l01923"></a>01923     fclose(GLPK_R_Out);
<a name="l01924"></a>01924 
<a name="l01925"></a>01925     <span class="keywordtype">int</span> itmp1,itmp2;
<a name="l01926"></a>01926     sscanf(tmp,<span class="stringliteral">"%d %d %lf\n"</span>,&amp;itmp1,&amp;itmp2,&amp;wynik);
<a name="l01927"></a>01927 
<a name="l01928"></a>01928     <a class="code" href="main_8c.html#bc046b760068e2015d1f943257ad1c9d">wynikAlokacja</a>[<a class="code" href="main_8c.html#99a3a311f73faef2c0af730e7f4dd00b">GLPK_R</a>] = wynik;
<a name="l01929"></a>01929     <a class="code" href="main_8c.html#b0c1a864c503ead10e2426d29c03fcc5">wynikCzas</a>[<a class="code" href="main_8c.html#99a3a311f73faef2c0af730e7f4dd00b">GLPK_R</a>] = <a class="code" href="main_8c.html#6ced5c44871ebf39b65910b5726a3de0">czasAlgorytmu</a>;
<a name="l01930"></a>01930 
<a name="l01931"></a>01931     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>!=1)
<a name="l01932"></a>01932         <span class="keyword">remove</span>(nazwaPlikuWyjsciowegoGLPK_R_out);
<a name="l01933"></a>01933 
<a name="l01934"></a>01934     <span class="comment">/* Parse'owanie loga zadania zrelaksowanego */</span>
<a name="l01935"></a>01935     <span class="comment">/*</span>
<a name="l01936"></a>01936 <span class="comment">     * @todo</span>
<a name="l01937"></a>01937 <span class="comment">     */</span>
<a name="l01938"></a>01938     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>!=1)
<a name="l01939"></a>01939         <span class="keyword">remove</span>(nazwaPlikuWyjsciowegoGLPK_R_log);
<a name="l01940"></a>01940 
<a name="l01941"></a>01941     <span class="comment">/* ROZWIAZANIE DOKLADNE */</span>
<a name="l01942"></a>01942     wynik = -1;
<a name="l01943"></a>01943 
<a name="l01944"></a>01944     <span class="comment">/* Stworzenie modelu zadania GLPK - dokladnego */</span>
<a name="l01945"></a>01945     <span class="keywordtype">char</span> nazwaPlikuModeluGLPK_D[256];
<a name="l01946"></a>01946     tmpnam(nazwaPlikuModeluGLPK_D);
<a name="l01947"></a>01947     strcat(nazwaPlikuModeluGLPK_D,<span class="stringliteral">"_D.mod"</span>);
<a name="l01948"></a>01948 
<a name="l01949"></a>01949     FILE * KP01_D_model = fopen(nazwaPlikuModeluGLPK_D,<span class="stringliteral">"w"</span>);
<a name="l01950"></a>01950     <span class="keywordflow">if</span> (KP01_R_model==NULL)
<a name="l01951"></a>01951     {
<a name="l01952"></a>01952         printf(<span class="stringliteral">"Blad, nie mozna utworzyc tymczasowego pliku do zapisu modelu GLPK!\n"</span>);
<a name="l01953"></a>01953         <span class="keywordflow">return</span>;
<a name="l01954"></a>01954     }
<a name="l01955"></a>01955     fprintf(KP01_D_model,<span class="stringliteral">"%s"</span>,<a class="code" href="main_8h.html#647b0fdf81ddfa7573e0f8fcd0708e13">KP01_D</a>);
<a name="l01956"></a>01956     fclose(KP01_D_model);
<a name="l01957"></a>01957 
<a name="l01958"></a>01958     <span class="keywordtype">char</span> nazwaPlikuWyjsciowegoGLPK_D_out[256], nazwaPlikuWyjsciowegoGLPK_D_log[256];
<a name="l01959"></a>01959 
<a name="l01960"></a>01960     tmpnam(nazwaPlikuWyjsciowegoGLPK_D_out);
<a name="l01961"></a>01961     strcat(nazwaPlikuWyjsciowegoGLPK_D_out,<span class="stringliteral">"_D.out"</span>);
<a name="l01962"></a>01962 
<a name="l01963"></a>01963     tmpnam(nazwaPlikuWyjsciowegoGLPK_D_log);
<a name="l01964"></a>01964     strcat(nazwaPlikuWyjsciowegoGLPK_D_log,<span class="stringliteral">"_D.log"</span>);
<a name="l01965"></a>01965 
<a name="l01966"></a>01966     sprintf(wywolanieGLPSOL,<span class="stringliteral">"glpsol.exe -d %s -m %s -w %s --log %s"</span>,nazwaPlikuDanychGLPK,nazwaPlikuModeluGLPK_D,nazwaPlikuWyjsciowegoGLPK_D_out,nazwaPlikuWyjsciowegoGLPK_D_log);
<a name="l01967"></a>01967 
<a name="l01968"></a>01968     <a class="code" href="main_8c.html#e9284b236f128677657631ae56843cae" title="Funkcja wstrzymuje dzialanie programu na okreslona liczbe sekund.">CzasStart</a>();
<a name="l01969"></a>01969     system(wywolanieGLPSOL);
<a name="l01970"></a>01970     <a class="code" href="main_8c.html#2cc2c7e7811c4a88e4dc3ee60b801508">CzasStop</a>();
<a name="l01971"></a>01971 
<a name="l01972"></a>01972     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a> != 1)
<a name="l01973"></a>01973         <span class="keyword">remove</span>(nazwaPlikuModeluGLPK_D);
<a name="l01974"></a>01974 
<a name="l01975"></a>01975     <span class="comment">/* Parse'owanie pliku wyjsciowego algorytmu dokladnego */</span>
<a name="l01976"></a>01976     FILE * GLPK_D_Out = fopen(nazwaPlikuWyjsciowegoGLPK_D_out,<span class="stringliteral">"a+"</span>);
<a name="l01977"></a>01977     fgets(tmp,128,GLPK_D_Out);
<a name="l01978"></a>01978     fgets(tmp,128,GLPK_D_Out);
<a name="l01979"></a>01979     fclose(GLPK_D_Out);
<a name="l01980"></a>01980 
<a name="l01981"></a>01981     sscanf(tmp,<span class="stringliteral">"%d %lf\n"</span>,&amp;itmp1,&amp;wynik);
<a name="l01982"></a>01982 
<a name="l01983"></a>01983     <a class="code" href="main_8c.html#bc046b760068e2015d1f943257ad1c9d">wynikAlokacja</a>[<a class="code" href="main_8c.html#0ac59573db46e3d633836e727f08aa0e">GLPK_D</a>] = wynik;
<a name="l01984"></a>01984     <a class="code" href="main_8c.html#b0c1a864c503ead10e2426d29c03fcc5">wynikCzas</a>[<a class="code" href="main_8c.html#0ac59573db46e3d633836e727f08aa0e">GLPK_D</a>] = <a class="code" href="main_8c.html#6ced5c44871ebf39b65910b5726a3de0">czasAlgorytmu</a>;
<a name="l01985"></a>01985 
<a name="l01986"></a>01986     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a> != 1)
<a name="l01987"></a>01987         <span class="keyword">remove</span>(nazwaPlikuWyjsciowegoGLPK_D_out);
<a name="l01988"></a>01988 
<a name="l01989"></a>01989     <span class="comment">/*</span>
<a name="l01990"></a>01990 <span class="comment">     * parse'owanie loga</span>
<a name="l01991"></a>01991 <span class="comment">     *</span>
<a name="l01992"></a>01992 <span class="comment">     *</span>
<a name="l01993"></a>01993 <span class="comment">     *</span>
<a name="l01994"></a>01994 <span class="comment">     */</span>
<a name="l01995"></a>01995     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a> != 1)
<a name="l01996"></a>01996         <span class="keyword">remove</span>(nazwaPlikuWyjsciowegoGLPK_D_log);
<a name="l01997"></a>01997 
<a name="l01998"></a>01998     <span class="comment">/* Posprzatanie */</span>
<a name="l01999"></a>01999     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a> != 1)
<a name="l02000"></a>02000         <span class="keyword">remove</span>(nazwaPlikuDanychGLPK);
<a name="l02001"></a>02001 }
<a name="l02002"></a>02002 
<a name="l02003"></a>02003 <span class="comment">/* ======================================================================</span>
<a name="l02004"></a>02004 <span class="comment"> *  Rozwiaz</span>
<a name="l02005"></a>02005 <span class="comment"> *</span>
<a name="l02006"></a>02006 <span class="comment"> *  @brief Rozwiazuje problem wybranym algorytmem.</span>
<a name="l02007"></a>02007 <span class="comment"> *</span>
<a name="l02008"></a>02008 <span class="comment"> *  @param nazwaAlgorytmu</span>
<a name="l02009"></a>02009 <span class="comment"> * ====================================================================== */</span>
<a name="l02010"></a><a class="code" href="main_8c.html#b992ab2c9b3d0c6a6b293f8d110d8cbc">02010</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#b992ab2c9b3d0c6a6b293f8d110d8cbc">Rozwiaz</a>(<span class="keywordtype">int</span> nazwaAlgorytmu)
<a name="l02011"></a>02011 {}
<a name="l02012"></a>02012 
<a name="l02013"></a>02013 
<a name="l02014"></a>02014 
<a name="l02015"></a>02015 <span class="comment">/* ======================================================================</span>
<a name="l02016"></a>02016 <span class="comment"> *  MAIN</span>
<a name="l02017"></a>02017 <span class="comment"> * ====================================================================== */</span>
<a name="l02018"></a><a class="code" href="main_8c.html#0ddf1224851353fc92bfbff6f499fa97">02018</a> <span class="keywordtype">int</span> <a class="code" href="main_8c.html#0ddf1224851353fc92bfbff6f499fa97">main</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])
<a name="l02019"></a>02019 {
<a name="l02020"></a>02020     printf(<span class="stringliteral">"%s\n"</span>,<a class="code" href="main_8h.html#647b0fdf81ddfa7573e0f8fcd0708e13">KP01_D</a>);
<a name="l02021"></a>02021     printf(<span class="stringliteral">"%s\n"</span>,<a class="code" href="main_8h.html#689c7814b58c9ff6a60412016bb1ab9f">KP01_R</a>);
<a name="l02022"></a>02022 
<a name="l02023"></a>02023     <span class="keywordflow">if</span> (argc==1)
<a name="l02024"></a>02024         <a class="code" href="main_8c.html#32d9cda086dbd06f8c1fe3f430611d9a" title="Wczytuje dane z pliku.">WczytajDaneWejsciowe</a>(<span class="stringliteral">"dane/dane_1000.txt"</span>);
<a name="l02025"></a>02025     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (argc==2)
<a name="l02026"></a>02026         <a class="code" href="main_8c.html#32d9cda086dbd06f8c1fe3f430611d9a" title="Wczytuje dane z pliku.">WczytajDaneWejsciowe</a>(argv[1]);
<a name="l02027"></a>02027     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (argc==3)
<a name="l02028"></a>02028     {
<a name="l02029"></a>02029         <a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a> = atoi(argv[2]);
<a name="l02030"></a>02030         <a class="code" href="main_8c.html#32d9cda086dbd06f8c1fe3f430611d9a" title="Wczytuje dane z pliku.">WczytajDaneWejsciowe</a>(argv[1]);
<a name="l02031"></a>02031     }
<a name="l02032"></a>02032 
<a name="l02033"></a>02033     <a class="code" href="main_8c.html#e9284b236f128677657631ae56843cae" title="Funkcja wstrzymuje dzialanie programu na okreslona liczbe sekund.">CzasStart</a>();
<a name="l02034"></a>02034     <a class="code" href="main_8c.html#cdd4e11b1fc38e16d036b25d02df00f0" title="Implementacja rozwiazania zrelaksowanego problemu KP01&amp;lt;=K.">Relaksacja</a>();
<a name="l02035"></a>02035     <a class="code" href="main_8c.html#2cc2c7e7811c4a88e4dc3ee60b801508">CzasStop</a>();
<a name="l02036"></a>02036     <a class="code" href="main_8c.html#b0c1a864c503ead10e2426d29c03fcc5">wynikCzas</a>[<a class="code" href="main_8c.html#e41c8500c68b74939c9beab3ff16990e">REL</a>] = <a class="code" href="main_8c.html#6ced5c44871ebf39b65910b5726a3de0">czasAlgorytmu</a>;
<a name="l02037"></a>02037     <span class="comment">//</span>
<a name="l02038"></a>02038     <a class="code" href="main_8c.html#e9284b236f128677657631ae56843cae" title="Funkcja wstrzymuje dzialanie programu na okreslona liczbe sekund.">CzasStart</a>();
<a name="l02039"></a>02039     <a class="code" href="main_8c.html#e85b4a7b11917a85362470a56128e990" title="Implementacja algorytmu H1 problemu KP01&amp;lt;=K.">AlgorytmH1</a>();
<a name="l02040"></a>02040     <a class="code" href="main_8c.html#2cc2c7e7811c4a88e4dc3ee60b801508">CzasStop</a>();
<a name="l02041"></a>02041     <a class="code" href="main_8c.html#b0c1a864c503ead10e2426d29c03fcc5">wynikCzas</a>[<a class="code" href="main_8c.html#3e4baeb2553d751ae0c007569655a137">H1</a>] = <a class="code" href="main_8c.html#6ced5c44871ebf39b65910b5726a3de0">czasAlgorytmu</a>;
<a name="l02042"></a>02042     <span class="comment">//</span>
<a name="l02043"></a>02043     <a class="code" href="main_8c.html#e9284b236f128677657631ae56843cae" title="Funkcja wstrzymuje dzialanie programu na okreslona liczbe sekund.">CzasStart</a>();
<a name="l02044"></a>02044     <a class="code" href="main_8c.html#7afb6457bc15f6a1fea27f461601e850" title="Implementacja algorytmu H2 problemu KP01&amp;lt;=K.">AlgorytmH2</a>();
<a name="l02045"></a>02045     <a class="code" href="main_8c.html#2cc2c7e7811c4a88e4dc3ee60b801508">CzasStop</a>();
<a name="l02046"></a>02046     <a class="code" href="main_8c.html#b0c1a864c503ead10e2426d29c03fcc5">wynikCzas</a>[<a class="code" href="main_8c.html#b5e8a97982062958fb8f58a428df09ee">H2</a>] = <a class="code" href="main_8c.html#6ced5c44871ebf39b65910b5726a3de0">czasAlgorytmu</a>;
<a name="l02047"></a>02047     <span class="comment">//</span>
<a name="l02048"></a>02048     <a class="code" href="main_8c.html#e9284b236f128677657631ae56843cae" title="Funkcja wstrzymuje dzialanie programu na okreslona liczbe sekund.">CzasStart</a>();
<a name="l02049"></a>02049     <a class="code" href="main_8c.html#c7f7228e325a7bc232d8940ccec07979" title="Implementacja algorytmu H2&amp;#39; problemu KP01&amp;lt;=K.">AlgorytmH2Prim</a>();
<a name="l02050"></a>02050     <a class="code" href="main_8c.html#2cc2c7e7811c4a88e4dc3ee60b801508">CzasStop</a>();
<a name="l02051"></a>02051     <a class="code" href="main_8c.html#b0c1a864c503ead10e2426d29c03fcc5">wynikCzas</a>[<a class="code" href="main_8c.html#e3ea6c504e916b75b4e44abeffdb8477">H2P</a>] = <a class="code" href="main_8c.html#6ced5c44871ebf39b65910b5726a3de0">czasAlgorytmu</a>;
<a name="l02052"></a>02052 
<a name="l02053"></a>02053     <a class="code" href="main_8c.html#e9284b236f128677657631ae56843cae" title="Funkcja wstrzymuje dzialanie programu na okreslona liczbe sekund.">CzasStart</a>();
<a name="l02054"></a>02054     <a class="code" href="main_8c.html#779e9c536e6db05731f94e52eabadfdd" title="Implementacja algorytmu H2 BIS problemu KP01&amp;lt;=K.">AlgorytmH2Bis</a>();
<a name="l02055"></a>02055     <a class="code" href="main_8c.html#2cc2c7e7811c4a88e4dc3ee60b801508">CzasStop</a>();
<a name="l02056"></a>02056     <a class="code" href="main_8c.html#b0c1a864c503ead10e2426d29c03fcc5">wynikCzas</a>[<a class="code" href="main_8c.html#13ba4f47dcd4f3e4a0dca6330c1916f2">H2B</a>] = <a class="code" href="main_8c.html#6ced5c44871ebf39b65910b5726a3de0">czasAlgorytmu</a>;
<a name="l02057"></a>02057 
<a name="l02058"></a>02058     <a class="code" href="main_8c.html#93e8ae2f06f58ce7bbc167f83da651f9" title="Umozliwia rozwiazanie problemu przez zewnetrzny solver (GLPK).">GLPK_R_D</a>();
<a name="l02059"></a>02059 
<a name="l02060"></a>02060 
<a name="l02061"></a>02061     <span class="comment">//</span>
<a name="l02062"></a>02062     <span class="keywordtype">int</span> i=0;
<a name="l02063"></a>02063     printf(<span class="stringliteral">"\n\nALG\tZ\t\tCZAS\tITERACJE\n"</span>);
<a name="l02064"></a>02064     <span class="keywordflow">for</span>(i=0;i&lt;=50;i++)
<a name="l02065"></a>02065         printf(<span class="stringliteral">"-"</span>);
<a name="l02066"></a>02066     <span class="keywordflow">for</span> (i=0; i&lt;7; i++)
<a name="l02067"></a>02067         printf(<span class="stringliteral">"\n%s\t%f\t%d\t%d"</span>,<a class="code" href="main_8c.html#29b4c5424b00e8c417f6cd28b91c6246">nazwy</a>[i],<a class="code" href="main_8c.html#bc046b760068e2015d1f943257ad1c9d">wynikAlokacja</a>[i],<a class="code" href="main_8c.html#b0c1a864c503ead10e2426d29c03fcc5">wynikCzas</a>[i],<a class="code" href="main_8c.html#2dc32c866ea1d483256f14beab4f0859">wynikIteracje</a>[i]);
<a name="l02068"></a>02068 
<a name="l02069"></a>02069     <span class="keywordtype">char</span> PlikOut[256];
<a name="l02070"></a>02070     strcpy(PlikOut,<a class="code" href="main_8c.html#e401adba12fa394291ec56e59e8120f4">nazwaPlikuWejsciowego</a>);
<a name="l02071"></a>02071     strcat(PlikOut,<span class="stringliteral">"_wyniki.txt"</span>);
<a name="l02072"></a>02072     printf(<span class="stringliteral">"\nWyniki zapisano do pliku %s.\n"</span>,PlikOut);
<a name="l02073"></a>02073     <a class="code" href="main_8c.html#8bd72ae940fe946b5943662c5c41fd7a" title="Generuje plik z rozwiazaniem zbiorczym dla wielu algorytmow.">WynikiZbiorcze</a>(PlikOut);
<a name="l02074"></a>02074 
<a name="l02075"></a>02075     <span class="keywordtype">int</span> <a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a> = 1;
<a name="l02076"></a>02076     <span class="keywordflow">for</span> (K=1; K&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>-1;K++)
<a name="l02077"></a>02077         ;
<a name="l02078"></a>02078 
<a name="l02079"></a>02079 
<a name="l02080"></a>02080 
<a name="l02081"></a>02081 
<a name="l02082"></a>02082     <a class="code" href="main_8c.html#01f7419ee78625ea24a0522dbd13917c">ZwolnijPamiec</a>();
<a name="l02083"></a>02083     <span class="keywordflow">return</span> 0;
<a name="l02084"></a>02084 }
<a name="l02085"></a>02085 
</pre></div></div>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>_</title></head>
<body><hr style="width: 100%; height: 2px;"><table style="text-align: left; width: 100%; height: 34px;" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="vertical-align: top;"><small style="font-family: Helvetica,Arial,sans-serif;"><span style="font-style: italic;">Dokumentacja pracy in&#380;ynierskiej,&nbsp;Kacper D. Tom&#380;y&#324;ski</span></small><big><br></big></td><td style="text-align: right; vertical-align: top;"><img style="width: 42px; height: 33px;" alt="" src="img/IAlogo0.gif" align="top" vspace="10"><small> &nbsp;</small><img style="width: 42px; height: 59px;" alt="" src="img/eiti.GIF"></td></tr></tbody></table><br></body></html>
